CSSセレクタでページを選択してページにドロップダウンメニュー(idがない)を選択しようとしましたが、動作させることができません。ここでは、ドロップダウン・コードは次のとおりです。セレクションを使用してIDなしのドロップダウンメニューを選択する方法
<select style="margin: 5px auto; width: 146px;" onchange="document.getElementById('11qq').src=this.options[this.selectedIndex].value;">
<option value="https://player.vimeo.com/video/158733095">Shakedown</option>
<option value="x">Placeholder</option>
<option value="https://player.vimeo.com/video/158815551">Race</option>
</select>
私は私が何であるかを知らないことを仮定している、私は注意してください(該当する映像データを検索したい後、各ドロップダウン要素を選択するには、次のコードを使用してみました私はそれがこのサイト上のすべてのドロップダウンのために働くしたいのですから、そもそもドロップダウン):私は、次のstackoverflow discussion(第二の答え)から得た
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import urllib2
url = "http://racing4everyone.eu/2016/03/12/formula-e-201516-round05-mexico/"
page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read(), "html.parser")
dropdown = [x.text for x in soup.find_all('option')]
driver = webdriver.Firefox()
driver.get("http://racing4everyone.eu/2016/03/12/formula-e-201516-round05-mexico/")
for x in dropdown:
Select droplist = new Select(driver.findElement(By.CSS_SELECTOR("select")));
droplist.selectByVisibleText(x);
frame_video = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "iframe[src*=video]")))
driver.switch_to.frame(frame_video)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".controls")))
page_source = driver.page_source
driver.close()
soup = BeautifulSoup(page_source, "html.parser")
script = soup.find_all("script")
# A couple of other operations follow to isolate the relevant data from the script data
Select droplist
一部。しかし、私は次のエラーを取得する:
Select droplist = new Select(driver.findElement(By.CSS_SELECTOR("select")));
^
SyntaxError: invalid syntax
'droplist.selectByVisibleText(x)'も有効ではないようですが、これと同じPythonは何ですか? –
'Florent、B'は、 – gavinsun
と言っています。 'Florent、B'は次のような方法で参照することができます: 'Select(driver.find_element_by_xpath(" // select [option = '"+ x +"'] ") ).select_by_visible_text(x) 'は それにはPythonのAPI以下: [PythonのAPIを](http://seleniumhq.github.io/selenium/docs/api/py/api.html) 私はそれを願っていますあなたを助けられる。 [select_by_visible_text](http://seleniumhq.github.io/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.select.html#selenium.webdriver.support.select.Select.select_by_visible_text) – gavinsun