How to make a program download images from a website, page by page, using id?

Asked

Viewed 996 times

3

I need to download several images from a website, where only the page number changes, but the id of tag img is always the same.

I wonder if there is any way to create a program that does this download and the page exchange, automatically.

The id is #backgroundImg. The page ?page=96, for example. Can in any language or medium.

I made that code, but I still can’t download it.

D:\>FOR %A IN (1,1,96) DO
    wget -A.jpg  http://www.servidor.com.br/#/edition/T3916843A?page=%Asection=1

I’m using wget in the prompt command.

  • What is the problem that this code presents?

  • You are creating a 3kb . html file and when you create more than one, it looks like this: index.html. 1; index.html. 2... None of these files are actually html.

  • I don’t understand why "wget -A.jpg http://www.servor.com.br/#/Edition/T3916843A? page=%Asection=1".. Obviously you won’t catch any image like this.. Did you take this code from some website? There was no other code?

  • No. This code I made myself. Because it’s so obvious that it won’t catch any image?

1 answer

1


The syntax of the loop for is incorrect, to declare and use a for it is necessary to prefix it with %%. It is also necessary to use the /L so that the range.

FOR /l %%A in (1, 1, 96) DO (
  :: Aqui você usa o wget para baixar o arquivo
  ECHO http://www.servidor.com.br/#/edition/T3916843A?page=%%Asection=1
)
PAUSE

Powershell

An alternative in Powershell:

1..96 | % { $paginas  += @{ $_ = "http://www.servidor.com.br/#/edition/T3916843A?page=$_`section=1"} }
$webClient = new-object System.Net.WebClient

foreach ($pagina in $paginas.getEnumerator()) {
   $webClient.DownloadFile($pagina.Value, "img$($pagina.Name)")
}
  • When trying this way, I get the following message "%A was unexpected at this time". I am using cmd version 6.3.9600

  • @Rivaldojunior Does this happen when you run the answer code? which system do you use?

  • This answer appears when giving enter in the full command. I use windows 8.1. I would try to download a college handbook, but I have how to create the pdf with the Google Chrome, in the handout print option, which the system itself gives. The idea was to make a code that was downloaded by the ID tag IMG

  • @Rivaldojunior Posted an alternative in Powershell, create a file and put the code in it, save the file with the extension ps1, then run it through Windows Powershell.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.