如何获取此站点的所有图像:http://www.theft-alerts.com 我们需要19页的图片。我们已经有了这个代码,但它还不起作用。我们要新地图上的图像。在
#!/usr/bin/python
import [urllib2][1]
from bs4 import BeautifulSoup
from urlparse import urljoin
url = "http://www.theft-alerts.com/index-%d.html"
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page, "html.parser")
base = "http://www.theft-alerts.com"
images = [urljoin(base,a["href"]) for a in soup.select("td a[href^=images/]")]
for url in images:
img = BeautifulSoup(urllib2.urlopen(url).read(),"lxml").find("img")["src"]
with open("myimages/{}".format(img), "w") as f:
f.write(urllib2.urlopen("{}/{}".format(url.rsplit("/", 1)[0], img)).read())
您需要遍历每一页并提取图像,您可以一直循环,直到文本
"Next"
的锚点位于类resultnav
的代码标记中:这给了你所有19页的图片。在
相关问题 更多 >
编程相关推荐