Web scraping 使用BeautifulSoup--Python刮表

Web scraping 使用BeautifulSoup--Python刮表,web-scraping,beautifulsoup,Web Scraping,Beautifulsoup,我正试图从这个网站上抓取一张桌子: 我正在使用以下代码: import requests from bs4 import BeautifulSoup URL = 'https://covidactnow.org/state/CA' page = requests.get(URL) soup = BeautifulSoup(page.content, 'html.parser') soup.find_all('tr') 我认为代码应该找到该表,但它返回一个空列表。@KunduK是正确的。你

我正试图从这个网站上抓取一张桌子:

我正在使用以下代码:

import requests
from bs4 import BeautifulSoup

URL = 'https://covidactnow.org/state/CA'
page = requests.get(URL)

soup = BeautifulSoup(page.content, 'html.parser')

soup.find_all('tr')

我认为代码应该找到该表,但它返回一个空列表。

@KunduK是正确的。你需要使用硒

import time
from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome(executable_path='Your:/Path/to/chromedriver.exe') 
driver.get("https://covidactnow.org/state/CA")
time.sleep(5)
html = driver.page_source
tables = pd.read_html(html)
data = tables[-1]
driver.quit()

数据由java脚本呈现。您需要使用像selenium这样的浏览器工具。Beauty soup无法处理java脚本。您好亲爱的Prakar-非常感谢您分享您的想法并提供帮助。我想学习,我只是潜入所有这些BS4和selenium的东西。问题是-我是否必须先安装webdriver-才能在我的winmachine上运行此示例代码!?很高兴听到你的声音——zerohi@zero是的,你实际上需要安装selenium。具体来说,pip安装selenium应该完成这项工作。接下来,您需要下载与您的chrome版本匹配的chrome驱动程序,并在下载到上述驱动程序路径后提供exe路径。如果我不清楚,请告诉我