我试图从这里抓取每日梦幻棒球预测:https://www.numberfire.com/mlb/daily-fantasy/daily-baseball-projections/batters
我想通过“平台”表格下拉选项导航,以使用selenium获取绘图投影(FanDuel设置为表格默认值)。根据这个答案Selenium (Python): How to insert value on a hidden input?我正在尝试更改类“dfs选项drop value”的隐藏值
from selenium import webdriver
driver = webdriver.Chrome('/Applications/chromedriver')
URL = 'https://www.numberfire.com/mlb/daily-fantasy/daily-baseball-projections/batters'
driver.get(URL)
elem = driver.find_element_by_xpath(
'//i[@class="nf-icon icon-caret-down active"]'
'/following-sibling::input[@type="hidden"]')
value = driver.execute_script('return arguments[0].value;', elem)
print("Before update, hidden input value = {}".format(value))
driver.execute_script('''
var elem = arguments[0];
var value = arguments[1];
elem.value = value;
''', elem, '4')
value = driver.execute_script('return arguments[0].value;', elem)
print("After update, hidden input value = {}".format(value))
# Then using beautiful soup
page = driver.page_source
soup = BeautifulSoup(page.content, 'html.parser')
dfs选项的drop值会根据需要进行更改,但页面仍呈现扇形投影,因此,显然这不是适当的表更改。请注意,这个特定的表没有带有选项值的“select”标记,因此Selenium dropdown menu和python - scraping tables by navigating different options in drop down list之类的答案将不起作用
有什么想法吗
要打开该下拉列表并选择“FanDuel”,您可以执行以下操作:
相关问题 更多 >
编程相关推荐