我正试图从bing刮掉多页图像。目前,下面的脚本可以保存28张图片,但我需要下载更多图像。
这是我现在正在使用的东西(从this article偷猎,因为我是菜鸟):
from bs4 import BeautifulSoup
import requests
import re
import urllib2
import os
def get_soup(url):
return BeautifulSoup(requests.get(url).text)
image_type = "ant"
query = "ant"
url = "http://www.bing.com/images/search?q=" + query + "&qft=+filterui:color2-bw+filterui:imagesize-large&FORM=R5IR3"
soup = get_soup(url)
images = [a['src'] for a in soup.find_all("img", {"src": re.compile("mm.bing.net")})]
for img in images:
raw_img = urllib2.urlopen(img).read()
cntr = len([i for i in os.listdir("images") if image_type in i]) + 1
f = open("images/" + image_type + "_"+ str(cntr), 'wb')
f.write(raw_img)
f.close()
如何修改上述内容以浏览多页bing图像搜索而不只是一页?