如何使用Python Beautiful Soup或Investpy从Investing.com刮擦可扩展的桌子?

发布于 2025-01-22 14:27:41 字数 948 浏览 0 评论 0 原文

https://www.investing.com/economic-calendar/initial- 如该问题所述, Robless-Claims-294

我尝试在此链接中刮擦数据表。但是,我只能刮擦数据的前几行,直到“显示更多”按钮。除Web刮擦外,我还尝试了Investpy.ecomonic_calendar(),但是过滤参数是如此随机,以至于我无法直接提取失业者索赔数据。有人可以帮我吗?

url = 'https://www.investing.com/economic-calendar/initial-jobless-claims-294'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
table1 = soup.find('table', id='eventHistoryTable294')
headers = []
for i in table1.find_all('th'):
  title = i.text
  headers.append(title)

mydata = pd.DataFrame(columns = headers)
table_rows = table1.find_all('tr')

#$df_side = pd.DataFrame(mydata)
#x = df_side.head(100)

for j in table1.find_all('tr')[1:]:
  row_data = j.find_all('td')
  row = [i.text for i in row_data]
  length = len(mydata)
  mydata.loc[length] = row

print(mydata)

https://www.investing.com/economic-calendar/initial-jobless-claims-294

As stated in the question, I tried to web scrape a data table from this link. However, I was only able to scrape the first few lines of the data until the "show more" button. Except for web scraping, I ve also tried investpy.economic_calendar(), yet the filtering parameters are so random so that I could not extract the jobless claim data directly. Could somebody please help me with this?

url = 'https://www.investing.com/economic-calendar/initial-jobless-claims-294'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
table1 = soup.find('table', id='eventHistoryTable294')
headers = []
for i in table1.find_all('th'):
  title = i.text
  headers.append(title)

mydata = pd.DataFrame(columns = headers)
table_rows = table1.find_all('tr')

#$df_side = pd.DataFrame(mydata)
#x = df_side.head(100)

for j in table1.find_all('tr')[1:]:
  row_data = j.find_all('td')
  row = [i.text for i in row_data]
  length = len(mydata)
  mydata.loc[length] = row

print(mydata)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文