【问题标题】:Beautiful soup unable to find data from website with Div美丽的汤无法使用 Div 从网站上找到数据
【发布时间】:2019-09-16 07:47:30
【问题描述】:

我试图从网站抓取数据,但没有返回任何数据。

我尝试以多种方式提取它,但 div id ="app" 中保存的数据从未显示出来。

from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://westgate-production-4cb87.firebaseapp.com/super-contests/weekly-card/embed')
res = driver.execute_script('return document.documentElement.outerHTML')
driver.quit()

soup = BeautifulSoup(res, "lxml")
print(soup)

当我打印汤时,它只显示 div id ="app" 而不是 div 中的内容。我也尝试在汤中查找表格、表格行等,但它总是返回一个空白数据集。

我知道有许多类似的问题,但似乎没有一个涵盖没有数据显示的情况。

感谢您提供的任何帮助!

【问题讨论】:

    标签: python selenium beautifulsoup


    【解决方案1】:

    应用程序需要时间来完全加载页面。提供一些 sleep() 来加载页面,然后使用 driver.page_source 来获取整个 html 内容。

    from bs4 import BeautifulSoup
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get('https://westgate-production-4cb87.firebaseapp.com/super-contests/weekly-card/embed')
    time.sleep(5)
    res=driver.page_source
    driver.quit()
    
    soup = BeautifulSoup(res, "lxml")
    print(soup)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-21
      • 2022-10-20
      • 2016-12-18
      • 1970-01-01
      • 2020-09-28
      • 2021-10-01
      • 1970-01-01
      相关资源
      最近更新 更多