from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
import pandas as pd
chrome_options = webdriver.ChromeOptions()
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.maximize_window()
code = "600970"
def getData(code):
url="http://f10.eastmoney.com/f10_v2/FinanceAnalysis.aspx?code=sh{}#lrb-0".format(code)
browser.get(url)
thepath="/html/body/div[1]/div[2]/div[7]/div[2]/table"
revenue=browser.find_elements_by_xpath(thepath)[0]
return revenue
x=getData(code).get_attribute("outerHTML")
fh=open(r"/tmp/data.html","w")
fh.write(x)
fh.close()
上面的代码运行后,获得了部分数据
原网页的许多数据,需要鼠标左键才能获得,数据多时,需要点击多次.
需求:获得这个网页的数据
http://f10.eastmoney.com/f10_...
我的尝试:模拟鼠标左键,显示更多数据后,保存.
Actions action = new Actions(driver)
actions.move_to_element(browser.find_elements_by_xpath('//*[@id="lrb_next"]'))[0].click().perform()
失败了,请专家解答,谢谢