Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium-将值插入下拉菜单(不存在“选择”标记)_Python_Selenium_Selenium Webdriver_Beautifulsoup_Drop Down Menu - Fatal编程技术网

Python Selenium-将值插入下拉菜单(不存在“选择”标记)

Python Selenium-将值插入下拉菜单(不存在“选择”标记),python,selenium,selenium-webdriver,beautifulsoup,drop-down-menu,Python,Selenium,Selenium Webdriver,Beautifulsoup,Drop Down Menu,我试图从这里获得每日梦幻棒球的预测: 我想浏览“平台”表格下拉选项,以获取DraftKings的投影。使用selenium将FanDuel设置为表格默认值。根据这个答案,我试图更改类“dfs选项drop value”的隐藏值 from selenium import webdriver driver = webdriver.Chrome('/Applications/chromedriver') URL = 'https://www.numberfire.com/mlb/daily-fanta

我试图从这里获得每日梦幻棒球的预测:

我想浏览“平台”表格下拉选项,以获取DraftKings的投影。使用selenium将FanDuel设置为表格默认值。根据这个答案,我试图更改类“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值会根据需要进行更改,但页面仍呈现扇形投影,因此,显然这不是适当的表更改。请注意,这个特定的表没有带有选项值的“选择”标记,因此诸如和之类的答案将不起作用


有什么想法吗?

要打开该下拉列表并选择“FanDuel”,您可以执行以下操作:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#This will open the drop-down dialog
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//span[@class='title' and(contains(text(),'Platform'))]/../div[@class='custom-drop']"))).click()

#This will select DraftKings from the open drop-down dialog.
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//ul[contains(@class,'active')]//li[@data-value='4']"))).click()


太好了,谢谢!不客气,我的朋友!