【问题标题】:Downloading image and comments from 9gag using python使用 python 从 9gag 下载图像和评论
【发布时间】:2018-07-07 17:17:07
【问题描述】:

我想使用 9gag 的图片和该图片的前 10 个 cmets。我正在尝试使用 python 提取图像。我不知道该怎么做。

BASE_URL = 'https://9gag.com/'

def get_image_soup(section):
    url = BASE_URL + section
    source_code = requests.get(url)
    plain_text = source_code.text
    soup = bs(plain_text)
    return soup

soup = get_image_soup(BASE_URL + 'funny')

看起来文章的链接在“GAG.App.LoadConfig”中。如何拉取文章的链接?

【问题讨论】:

    标签: python html json web-scraping automation


    【解决方案1】:

    您需要解析 html 以获取图像和评论。 cmets 与图像位于不同的页面中,因此您需要为每个图像生成链接,然后在那里解析 cmets。要拉取文章的链接,您需要获取每个图像的 id 并使用它来生成新链接。如果图像的 id 是 avOXW7d,那么您的 url 需要是 https://9gag.com/gag/avOXW7d

    我建议使用 API 而不是为这个任务解析 html,因为解析 html 非常耗时。通过 Google 快速搜索,我发现 9gag 有一些非官方的 API。以下是您可以使用的一些链接。 Link 1Link 2.

    【讨论】:

      猜你喜欢
      • 2018-11-22
      • 2015-04-02
      • 2022-06-25
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      相关资源
      最近更新 更多