Hello! Recently faced the problem of downloading images from the site litres.ru.

There is some url: ... / pages / read_book_online /? File = 15177364 & page = 0 & rt = w640 & ft = gif


The browser interpreter perceives it as a picture and I want to download it, but there was a problem, there is no direct link to the picture (Gif). That is, when trying to download a picture via HttpRequest (via Stream, HttpResponse, etc.) or webclient.DownloadFile (url, "filename.gif"), the page itself is downloaded (ContentType = text / html). In a browser, the page looks like this: enter image description here

Question: How can I download a picture like "lkm -> save as image"? I heard about pseudo-browsers (correct if not so called), which load api directly, simulating the work of a real browser, and can calculate everything. Is there something like this in c #? Or is there another solution? In general, I need to download a lot of similar pages. Thank!

PS If not difficult, describe in more detail the way, I think many will be interested :)

UPD : preferably without a browser from Windows Forms enter image description here Request for receiving pictures: enter image description here

  • Nothing is clear. So is there a link to the picture or not? How to download a picture to which there is no link? What needs to be done? Fiddler caught the request to download pictures by the browser? The headers looked request? - tym32167
  • @ tym32167 photo request for download added, there is no link to the picture. You need to simulate the browser "lkm -> save image as" - Xambey
  • Why don't you just give a link to the picture itself? Googling, I found most likely from where you download , took the first link from the Internet, not gif , but still the resource is like that. Next, I have downloaded the image from this site without any problems with the usual WebClient.DownloadFile . The question is, what are the problems and how can we reproduce this problem? - EvgeniyZ
  • @EvgeniyZ yes if you google it, then you can find a ready grabber - tym32167
  • 2
    This book costs less than 400 rubles. How to dine twice in the dining room what. Or one coffee in a cafe. Are you sure that there is no other way? - sanmai

1 answer 1

Solved a problem. To get the Content-Type: image / gif, image / gif instead of text / html, you MUST be specified in the Cookie SID (this is the authentication authentication on litres.ru :)). Download the book in Jpeg can be as follows:

 for (int i = 0; i < count; i++) { var bytes = web.DownloadData(name.Replace("page=", $"page={i}")); System.Drawing.Image img = System.Drawing.Image.FromStream(new MemoryStream(bytes)); img.Save($"{path}/page{i}.jpg", ImageFormat.Jpeg); } 
  • Can you describe the solution in more detail? With the 1st example of implementation (on the example of one page of the book / picture). Faced a similar problem, only I have the GIF format (not the point). I don’t understand how to turn a link like: litres.ru/pages/get_pdf_page/… into a gif-file (or save as a gif-file). Google Chrome renders it normally, but the download manager, for example, does not see it. I see from the example above that you substitute the page counter in the final link and save the jpeg as page {n}, but what is the final link? What should it be? >>> For Content- - A. Popov
  • @ A.Popov Give an example url, I do not remember what was there, but I can help mb - Xambey pm
  • Please look at this topic: ru.stackoverflow.com/q/935819/213987 - it was created by @ A.Popov with your question. - AK