我想从下一页下载图片http://wordpandit.com/learning-bin/visual-vocabulary/page/2/ 我用urllib下载了它,并用beauthoulsoup进行了解析。它包含许多URL,我只想要那些以.jpg结尾的URL,它们还有rel=“prettypoto[gallery]”标记。 如何使用Beautifulsoup来实现这一点? 链接的Eg http://wordpandit.com/wp-content/uploads/2013/02/Obliterate.jpg
#http://wordpandit.com/learning-bin/visual-vocabulary/page/2/
import urllib
import BeautifulSoup
import lxml
baseurl='http://wordpandit.com/learning-bin/visual-vocabulary/page/'
count=2
for count in range(1,2):
url=baseurl+count+'/'
soup1=BeautifulSoup.BeautifulSoup(urllib2.urlopen(url))#read will not be needed
#find all links to imgs
atag=soup.findAll(rel="prettyPhoto[gallery]")
for tag in atag:
soup2=BeautifulSoup.BeautifulSoup(tag)
imgurl=soup2.find(href).value
urllib2.urlopen(imgurl)
你的代码有很多不必要的东西。也许您稍后会使用它们,但是像将
count
指定为2
然后在for range
循环中使用它作为计数器的做法是没有意义的。下面是您想要的代码:相关问题 更多 >
编程相关推荐