简体   繁体   English

python从url下载图像

[英]python download images from url

This wont be easy to answer so I would like some guide instead: I want to download images form a webserver.这并不容易回答,所以我想要一些指南:我想从网络服务器下载图像。 I know how to get an image from a url, but i dont know how many pages I can find.我知道如何从 url 获取图像,但我不知道我能找到多少页。 (example, chapter 01 has 21 images, chapter 02 only 12...) (例如,第 01 章有 21 张图像,第 02 章只有 12 张...)

There is a combo box ( DropdownChoice ) on the webpage that tells how many pages are of that chapter.网页上有一个组合框 ( DropdownChoice ),用于说明该章节有多少页。 Is there a way I can get that info?有没有办法我可以得到这些信息?

if I get to know that, i can do a for from page 1 to page x and download every image.如果我知道,我可以第1页至第x页做和下载每一个形象。

fyi I am using python仅供参考,我正在使用 python

Thanks!谢谢!

As a quick hack, you could just download sequential pages until you get a 404 (or some other error).作为一个快速的技巧,您可以只下载连续的页面,直到出现 404(或其他一些错误)。 This isn't generally considered "nice", so use it with caution, but it will allow you to download all of the images easily.这通常不被认为是“好”的,因此请谨慎使用它,但它可以让您轻松下载所有图像。

Alternately, you can look at using the Scrapy package to help you download and parse webpages and images.或者,您可以考虑使用Scrapy包来帮助您下载和解析网页和图像。

This project in python downloads a number of images from a website pre-defined by the user.这个python项目从用户预定义的网站下载了许多图像。 I'm sure you can change it to suit your needs.我相信你可以改变它以满足你的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM