需要 Python 抓取工具的帮助
我正在尝试使用 urllib 和 python 来制作一个刮刀,我可以下载图像,但它们是缩略图,250x250 或更少。(我正在尝试 4chan,因为我喜欢一些图片线程) 我怎样才能获得完整的图像? 这是我的代码
import urllib2, urllib
from BeautifulSoup import BeautifulSoup
import re
import urlparse
i = 0
ext = "'src' : re.compile(r'(jpe?g)|(png)|$'"
url = raw_input("Enter URL here:")
ender = raw_input("Enter File Type Here(For Images enter 'img'):")
if ender == "img":
ender = 'img', {'src' : re.compile(r'(.jpe?g)|(.png)|(.gif)$')}
else:
if "." in ender:
end = ender
else:
end = ".%s" % ender
raw = urllib.urlopen(url)
soup = BeautifulSoup(raw)
parse = list(urlparse.urlparse(url))
for ender in soup.findAll(ender):
links = "%(src)s"% ender
print links
str(links)
if ".jpg" in links:
end = ".jpg"
if ".jpeg" in links:
end = ".jpeg"
if ".gif" in links:
end = ".gif"
if ".png" in links:
end = ".png"
i += 1
urllib.urlretrieve(links, "%s%s" % (i, end))
I am trying to use urllib with python to make a scraper, I can download the images, but they are a thumbnail, 250x250 or less.(I am trying of 4chan, Because I like some of the picture threads)
How can I get the full image?
here is my code
import urllib2, urllib
from BeautifulSoup import BeautifulSoup
import re
import urlparse
i = 0
ext = "'src' : re.compile(r'(jpe?g)|(png)|
"
url = raw_input("Enter URL here:")
ender = raw_input("Enter File Type Here(For Images enter 'img'):")
if ender == "img":
ender = 'img', {'src' : re.compile(r'(.jpe?g)|(.png)|(.gif)
)}
else:
if "." in ender:
end = ender
else:
end = ".%s" % ender
raw = urllib.urlopen(url)
soup = BeautifulSoup(raw)
parse = list(urlparse.urlparse(url))
for ender in soup.findAll(ender):
links = "%(src)s"% ender
print links
str(links)
if ".jpg" in links:
end = ".jpg"
if ".jpeg" in links:
end = ".jpeg"
if ".gif" in links:
end = ".gif"
if ".png" in links:
end = ".png"
i += 1
urllib.urlretrieve(links, "%s%s" % (i, end))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您可以单击查看更大的链接,因此图像标记周围的
中的 URL 指向完整图像。
因此,只需读取
href
属性的值,然后下载该值,而不是图像的src
属性。Because you can click to see a larger link, the URL in the
<a href="url">
that is around the image tag points to the full image.So just read the value of the
href
property, and download that instead of thesrc
property of the image.