我正在使用BeautifulSoup来提取图片,这对普通页面很有效。 现在我想从这样的网页中提取Chromebook的图片
https://twitter.com/banprada/statuses/829102430017187841
该页面显然包含指向另一个带有图像的页面的链接。这是我的代码,下载一个图片从上述链接,但我只是得到的人谁张贴的链接。在
import urllib.request
import os
from bs4 import BeautifulSoup
URL = "http://twitter.com/banprada/statuses/829102430017187841"
list_dir="D:\\"
default_dir = os.path.join(list_dir,"Pictures_neu")
opener = urllib.request.build_opener()
urllib.request.install_opener(opener)
soup = BeautifulSoup(urllib.request.urlopen(URL).read())
imgs = soup.findAll("img",{"alt":True, "src":True})
for img in imgs:
img_url = img["src"]
filename = os.path.join(default_dir, img_url.split("/")[-1])
img_data = opener.open(img_url)
f = open(filename,"wb")
f.write(img_data.read())
f.close()
有机会下载图片吗?在
非常感谢和问候, 安蒂
这就是使用Selenium+requests获得只提到的图像的方法
如果您想从页面上的iframes中获取all的图像(不包括可以通过代码获得的初始页面源上的图像):
^{pr2}$注意,您可以使用any ^{}
相关问题 更多 >
编程相关推荐