我在从下面的https://pregame.com/game-center/171763/consensus-archive抓取内容时遇到了麻烦。我使用的是“美丽的汤”,只得到HTML的片段,没有任何我能清楚看到的嵌入在代码中的数据。
这是我在几次尝试之后使用的最新一次代码迭代(这是一次只获取日期列的尝试,但我想获取整个表).
import pandas as pd
import requests
from bs4 import BeautifulSoup
url = 'https://pregame.com/game-center/171763/consensus-archive'
html = requests.get(url)
soup = BeautifulSoup(html.text, 'html.parser')
results = soup.find(class_ = "pg-move-list")
print(results.prettify())
dates = results.find_all("td", class_="pg-col pg-col--date")
for date in dates:
print(date, end = "\n"*2)
for date in dates:
data_date = date.find("p", class_= "pg-col-data")
print(data_date.text)HTML也是..。

意识到在这里和其他地方有许多类似的问题在网上,但我仍然停留在参考他们。提前谢谢你的帮助。
发布于 2022-08-24 18:54:13
以防这对任何人有帮助。创建以下代码,使用上面的答案访问API,然后循环遍历URL列表。
# Read CSV file
URLs = read_csv("URLs_1_250.csv")
# Convert column of URLs to a list
odds = URLs['URL'].tolist()
# Create empty dataframe to append new data to
nfl_data = pd.DataFrame()
# Loop through list of urls to scrape odds data
for i in tqdm(range(0,250)):
url = odds[i]
r = requests.get(url)
data = pd.DataFrame(r.json()['Items'])
nfl_data = nfl_data.append(data, ignore_index = True)
time.sleep(1)https://stackoverflow.com/questions/73435654
复制相似问题