【问题标题】:I am getting an empty list in python Beautiful Soup我在 python Beautiful Soup 中得到一个空列表
【发布时间】:2021-09-07 15:45:39
【问题描述】:

我在 scraping 列表之后才得到空白列表,但我尝试的一些标签就像 div 标签一样工作。 那么,有人能告诉我代码有什么问题吗?或者网站是否使用了 api 或任何阻止 scraping 它的东西?

This is the code which I am using to get the names of the songs

Image of the result I am getting from this code

如果我的问题不是很好,我很抱歉,因为我是 scraping 的新手,我不知道为什么它不起作用。

【问题讨论】:

  • “如果我的问题不好,我很抱歉”您可以按照加入时的建议在发布前阅读指南,这样您就不会那么抱歉了...How to Ask
  • 可能是权限错误。有些网站不允许您进行网络剪贴

标签: python beautifulsoup request


【解决方案1】:

首先,您应该提供您想要评估或需要帮助的代码。

您可以在此处查看其他可用问题以了解如何提问。一旦你提供了,我想你可能会得到你正在寻找的正确答案。

据我所知,您建议您检查您的回复的status_code,看看它是否有效

with open("test.html", "w") as f:
    f.write(response.text)

使用上面提到的功能,您可以看到您得到的响应,然后如果正确,您可以在使用开发工具检查时继续解析。

【讨论】:

    【解决方案2】:

    首先你的日期格式是错误的。应该是 yyyy-mm-dd 其次你在soup.find中给出了错误的标签

    检查一下:

      import requests as req
    
      from bs4 import BeautifulSoup as bs
    
      date = input("yyyy-mm-dd:").strip()
    
      html = req.get("https://www.billboard.com/charts/hot-100/{}".format(date))
    
      soup = bs(html.text,'lxml')
    
      songs_list = soup.find_all('span',class_="chart-element__information__song")
      
      songs_list = [song.text for song in songs_list]
    
      for song in songs_list:
    
            print(song)
    

    输出:- yyyy-mm-dd:2021-06-12

    黄油 好4U

    悬浮

    让门敞开

    留下你的眼泪

    桃子

    再亲我一下

    似曾相识

    海洋中的宇航员

    蒙特罗(请以你的名字呼唤我)

    没有你

    叛徒

    驾照

    .. . . . .

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      • 2017-12-07
      • 1970-01-01
      • 2019-04-01
      • 2015-04-27
      相关资源
      最近更新 更多