【发布时间】:2014-02-15 13:29:50
【问题描述】:
我没有做太多线程,但我想知道我是否可以同时将图像保存在网页上,而不是一次保存一个。
目前我的代码是后者:
while pageCount <= 5:
soup = BeautifulSoup(urllib2.urlopen("http://www.url.../%d" % pageCount))
for link in soup.find_all("div", class_="photo"):
pic = link.findAll('img')
url = re.search("(?P<url>https?://[^\s]+\.(?:jpe?g))", str(pic)).group("url")
count +=1
urllib.urlretrieve(url,'C:\Desktop/images/pics%s.jpg' % count)
pageCount +=1
我在想这个过程可以通过采用多线程方法来加速,但不确定如何。
谢谢
【问题讨论】:
-
你可以检查这个问题(使用 gevents):stackoverflow.com/questions/4119680/… 或者你可以考虑合并连接(stackoverflow.com/questions/2009243/…)
标签: python multithreading beautifulsoup