1
我开始学习使用Python和Selenium的Scrape网站。我选择硒因为我需要浏览网站,我也必须登录。使用Python/Selenium的Webscrape Flashscore
我写了一个脚本,能够打开一个Firefox窗口,并打开网站www.flashscore.com。有了这个脚本,我也能够登录并导航到他们拥有的不同体育节(主菜单)。
代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# open website
driver = webdriver.Firefox()
driver.get("http://www.flashscore.com")
# login
driver.find_element_by_id('signIn').click()
username = driver.find_element_by_id("email")
password = driver.find_element_by_id("passwd")
username.send_keys("*****")
password.send_keys("*****")
driver.find_element_by_name("login").click()
# go to the tennis section
link = driver.find_element_by_link_text('Tennis')
link.click()
#go to the live games tab in the tennis section
# ?????????????????????????????'
然后就更加困难。例如,我还想要导航到体育领域的“实时游戏”和“完成”选项卡。这部分不起作用。我尝试了很多东西,但是我无法进入这个标签。在分析网站时,我发现他们使用了一些Iframe。我也发现一些代码切换到Iframes窗口。但问题是,我无法找到要点击的选项卡的Iframe名称。也许iframes不是问题,我看错了方向。 (也许这个问题是由一些JavaScript引起的?)
任何人都可以请帮助我吗?
的反应非常感谢。一个问题。运行我的脚本时出现错误。 – timovic
在运行时这样的:从进口硒webdriver的 从selenium.webdriver.common.keys汇入selenium.webdriver.support.ui导入密钥 从selenium.webdriver.support进口expected_conditions为EC 从selenium.webdriver.common WebDriverWait 。由进口到 #打开网站 司机= webdriver.Firefox() driver.get( “http://www.flashscore.com”) #go在网球节 live_games_link =等待的比赛实况标签.until(EC.element_to_be_clickable((By.LINK_TEXT,“LIVE Games”))) live_games_link.click() – timovic
我得到错误:live_games_link = wait.until(EC.eleme nt_to_be_clickable((By.LINK_TEXT,“LIVE Games”))) NameError:name'wait'没有定义 – timovic