Police said the gang's automated software application - or bot - was able to bypass measures designed to identify robots, allowing it to book "practically all" of the appointments across Spain that are normally free and resell them for as much as 200 euros ($220) each.

In Spain, people seeking asylum or a residency visas must present documents to the police, for which long waits are common.

The leaders of the gang set up a company that rented out the bot out to intermediaries who then sold the appointments.

A police statement said the intermediaries as well as lawyers and advisers were aware of the existence of a hack "and of the corresponding problems they were causing to foreigners who, on many occasions, were in a situation of great vulnerability and desperation".

Among the arrested were the four alleged leaders of the gang in Barcelona and Valencia. In raids, the police confiscated documents and found more than 200,000 euros ($220,160) in cash.

The use of bots that can operate 24 hours a day for online activities such as buying music concert tickets is becoming an increasingly common tool used by ticket touts. Record bot traffic disrupted Taylor Swift concert ticket sales last year, drawing heat from U.S. senators.

($1 = 0.9084 euros)

(Reporting by Charlie Devereux; Editing by William Maclean)