我可以通过 Python 中的网络抓取从网页中获取数据。我的数据被提取到一个列表中。但不知道如何将该列表转换为数据框。有什么办法可以直接从网络抓取数据并将数据提取到 df 吗?这是我的代码:
import pandas as pd
import requests
from bs4 import BeautifulSoup
from tabulate import tabulate
from pandas import DataFrame
import lxml
# GET the response from the web page using requests library
res = requests.get("https://www.worldometers.info/coronavirus/")
# PARSE and fetch content using BeutifulSoup method of bs4 library
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table')[0]
df = pd.read_html(str(table))
# Here dumping the fetched data to have a look
print( tabulate(df[0], headers='keys', tablefmt='psql') )
print(df[0])