python - 想用 selenium 登陆网站,但是无法获取弹出的验证码 frame 的名称,无法切换frame无法控制
阿神
阿神 2017-04-18 09:48:39
0
1
286

http://wuxia.qq.com/cp/a20160... 天涯明月刀的网站,想自动领取奖励,登陆这块就遇到问题

打开网站后,点击登陆,切换到 loginIframe 登陆 frame 输入用户名密码正确,但是登陆后无法控制验证码所在的 frame ,看不出名字,没法切换也就无法控制

代码如下:

tyurl = "http://wuxia.qq.com/cp/a20160920tmfl/" username = "123456" pwd = "1234561" binary = FirefoxBinary("z:\\firefox\\firefox.exe") driver = webdriver.Firefox(firefox_binary=binary,executable_path = "z:\geckodrive\geckodriver.exe") driver.get(tyurl) driver.find_element_by_id("dologin").click() driver.switch_to_frame("loginIframe") # 等待账号密码登录窗口出现,点击账号密码登 WebDriverWait(driver, 10,1).until(EC.presence_of_element_located((By.ID,"switcher_plogin"))) driver.find_element_by_id("switcher_plogin").click() # 输入账号密码 WebDriverWait(driver, 30,1).until(EC.presence_of_element_located((By.ID,"login_button"))) for i in range(1,20): try: driver.find_element_by_id("u").click() driver.find_element_by_id("u").send_keys(username) driver.find_element_by_id("p").click() driver.find_element_by_id("p").send_keys(pwd) break except Exception, e: pass # 输入密码点击确定后无法定位验证码窗口 try: WebDriverWait(driver, 5,1).until(EC.presence_of_element_located((By.ID,"capImg"))) except Exception, e: pass # 找不到当前验证码窗口里的ID capImg print(driver.find_element_by_id("capImg").src)
阿神
阿神

闭关修行中......

membalas semua (1)
巴扎黑
你得跳进frame里面去 driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0]) driver.find_element_by_xpath('/html/body') 记得还要调出来 driver.switch_to.default_content()
    Muat turun terkini
    Lagi>
    kesan web
    Kod sumber laman web
    Bahan laman web
    Templat hujung hadapan
    Tentang kita Penafian Sitemap
    Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!