【问题标题】:Web Scraping problem through python, can't read html file?通过python进行网页抓取问题,无法读取html文件?
【发布时间】:2020-04-06 23:28:04
【问题描述】:

一直在使用 Python 进行网络抓取,最近我遇到了这个问题。 BeautifulSoup 似乎无法读取 html 文件。

例如,我试图从这个网站上抓取 https://www.thetvdb.com/series/initial-d/episodes/4889010

这是我的代码

from bs4 import BeautifulSoup
import requests
url_episode = 'https://www.thetvdb.com/series/initial-d/episodes/4889010'
print(url_episode)
getdetail_episode = requests.get(url_episode)
soup = BeautifulSoup(getdetail_episode.content,'html.parser')
print(soup.prettify())

我能够从其他链接中抓取数据,但不是这个。

我还应该做些什么来让它工作? 谢谢

更新 所以我检查了 Relp.it 和其他在线 python 编译器,代码有效。什么鬼?

它不能在我的计算机上使用我的 Sublime Text 或 Python IDLE 编译器?

我很困惑。

【问题讨论】:

    标签: python-3.x web-scraping beautifulsoup


    【解决方案1】:

    好吧,我想我想通了。 整个麻烦是由于从网页加载数据的延迟造成的,导致IDE认为没有数据可以抓取。

    最终使用 requests-html 而不是 BeautifulSoup 来解决它们。

    很像这样

    from bs4 import BeautifulSoup
    import requests
    from requests_html import HTMLSession
    session = HTMLSession()
    url_episode = 'https://www.thetvdb.com/series/initial-d/episodes/4889010'
    getdetail_episode = session.get(url_episode)
    soup = BeautifulSoup(getdetail_episode.content,'html.parser')
    print(soup.prettify())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-14
      • 2020-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      相关资源
      最近更新 更多