【发布时间】:2021-06-17 10:37:23
【问题描述】:
我希望对以下内容有所帮助。我正在尝试在此网站上抓取代码下拉列表的元素:https://live.hxro.io/tixwix
我的代码如下使用 selenium
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options
url = "https://live.hxro.io/tixwix"
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path = r'C:\geckodriver\chromedriver.exe',options = chrome_options)
driver.get(url)
tickers = driver.find_elements_by_class_name('lastprice-toggle')
tickers[0].text
这只会返回
'BTC\nLast Price\n$39,255.07'
由于它是一个 Ajax 调用,我不确定如何以有效的方式检索其他代码。我以为函数 find_element's' 会将所有元素返回到一个列表中,但我只得到第一个 tickers[1] 超出范围。
页面源截图: enter image description here
谢谢
【问题讨论】:
标签: python ajax selenium web-scraping