gpt4 book ai didi

python - 使用 Selenium 从表中抓取数据

转载 作者:行者123 更新时间:2023-12-02 16:23:58 25 4
gpt4 key购买 nike

我想从以下页面中抓取“符号”、“名称”和“ yield 电话 session 时间”下的所有公司信息:https://finance.yahoo.com/calendar/earnings

到目前为止,这只是公司名称,但出现错误:

"NoSuchElementException: 没有这样的元素: 无法定位元素: {"method":"xpath","selector":"//*[@id='cal-res-table']/div[1]/表/tbody/tr[1]/td[2]"}( session 信息:chrome=86.0.4240.198)”

from selenium import webdriver
import datetime

tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).isoformat() #get tomorrow in iso format as needed
url = "https://finance.yahoo.com/calendar/earnings?day="+tomorrow
print ("url: " + url)

driver = webdriver.Chrome("C:/Users/jrod94/Downloads/chromedriver_win32/chromedriver.exe")
driver.get(url)
element = driver.find_element_by_xpath("//*[@id='cal-res-table']")
Companies = [a.get_attribute("Company") for a in element]

driver.close()

最佳答案

使用 pandas 怎么样?

import datetime
import pandas as pd

pd.set_option('display.max_column',None)
tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).isoformat() #get tomorrow in iso format as needed'''
url = pd.read_html("https://finance.yahoo.com/calendar/earnings?day="+tomorrow, header=0)
table = url[0]
print(table)

输出:-

  Symbol                         Company  Earnings Call Time EPS Estimate  \
0 WBAI 500.Com Ltd After Market Close -
1 BRBR Bellring Brands Inc TAS 0.19
2 BKE Buckle Inc Before Market Open 0.54
3 BNR Burning Rock Biotech Ltd TAS -0.12
4 IEC IEC Electronics Corp TAS -
5 GEOS Geospace Technologies Corp TAS -
6 DREM Dream Homes & Development Corp Time Not Supplied -
7 DXLG Destination XL Group Inc Before Market Open -
8 FL Foot Locker Inc Before Market Open 0.61
9 HHR HeadHunter Group PLC TAS 0.14
10 HHR HeadHunter Group PLC Before Market Open 0.14
11 RMR RMR Group Inc Before Market Open 0.39
12 GSX GSX Techedu Inc Before Market Open -0.31
13 GSX GSX Techedu Inc TAS -0.31
14 HIBB Hibbett Sports Inc Before Market Open 0.45
15 HAYN Haynes International Inc TAS -0.7
16 IIIV i3 Verticals Inc TAS 0.18
17 AIHS Senmiao Technology Ltd Before Market Open

关于python - 使用 Selenium 从表中抓取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64907303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com