需要 Python 抓取工具的帮助

发布于 2024-11-25 13:35:32 字数 991 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2024-12-02 13:35:32

由于您可以单击查看更大的链接,因此图像标记周围的 中的 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 the src property of the image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文