我正试图在2017-08-01的这个日期刮掉雅虎的分裂,分组显示在上传的图片中,
在2017-08-01分裂
根据上传的图片,我应该得到'SVU', 这是我的代码,
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.get("https://finance.yahoo.com/calendar/splits?day=2017-08-01")
soup = BeautifulSoup(driver.page_source, "lxml")
driver.quit()
我不知道如何获取第一列('SVU')的数据, 请提前帮助,谢谢。
答案 0 :(得分:0)
试试这个:
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.get("https://finance.yahoo.com/calendar/splits?day=2017-08-01")
soup = BeautifulSoup(driver.page_source, "lxml")
Symbol=soup.find("td",{"class" :"data-col0 Ta(start) Pend(15px) Pstart(15px) W(10%)"}).text
company=soup.find("td",{"class" :"data-col1 Ta(start) Pend(10px) W(20%)"}).text
payable_on=soup.find("span",{"data-reactid" :"41"}).text
ex_date=soup.find("span",{"data-reactid" :"43"}).text
optionalable=soup.find("td",{"class" :"data-col4 Ta(end) Pstart(15px) W(10%)"}).text
ratio=soup.find("td",{"class" :"data-col5 Ta(end) Pstart(15px) W(10%)"}).text
announced=soup.find("span",{"data-reactid" :"47"}).text
print("Symbol is {} \n Company is {} \n Payable on {} \n Ex Date {} \n Optionable ? {} \n ratio {} \n announced {}".format(Symbol,company,payable_on,ex_date,optionalable,ratio,announced))
driver.quit()
输出:
Symbol is SVU
Company is Supervalu
Payable on 0.00%
Ex Date Aug 01
Optionable ? Y
ratio 1.00 - 7.00
announced Aug 01
答案 1 :(得分:0)
试试这个。它会根据您的要求获取所需的所有数据。
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.get("https://finance.yahoo.com/calendar/splits?day=2017-08-01")
soup = BeautifulSoup(driver.page_source, "lxml")
driver.quit()
item = soup.select("tr.data-rowSVU")[0]
for data in item.select("td"):
print(data.text)
结果:
SVU
Supervalu
Aug 01
Aug 01
Y
1.00 - 7.00
Aug 01