此代码的作用范围仅限于使用硒从tradingview抓取数据并将结果打印到屏幕上。不确定如何将其传递给Beautiful Soup,因为似乎无法使用硒打印到csv文件吗?谁能帮忙。非常感谢。
工作代码
from selenium import webdriver
url = 'http://www.tradingview.com/screener'
driver = webdriver.Firefox()
driver.get(url)
# will give a list of all tickers
tickers = driver.find_elements_by_css_selector('a.tv-screener__symbol')
# will give a list of all close values
close_values = driver.find_elements_by_xpath("//td[@class = 'tv-data-table__cell tv-screener-table__cell tv-screener-table__cell--numeric']/span")
for index in range(len(tickers)):
print("Row " + tickers[index].text + " " + close_values[index].text + " " )
答案 0 :(得分:0)
您可以使用driver.page_source
获取网页的HTML源。要在BS中使用它,您可以执行以下操作:
soup = BeautifulSoup(driver.page_source, 'lxml')
#do whatever you want using soup object