需要账号密码登录的网页怎么实现Python抓取
如上需要账号密码登录的网页怎么实现Python抓取
如上需要账号密码登录的网页怎么实现Python抓取
2017-09-01
from selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.common.exceptions import NoSuchElementExceptionfrom selenium.webdriver.common.by import By
wd = webdriver.Firefox()
wd.get("http://www.renren.com")
wd.maximize_window()try: """这段可以查看selenium的源码,属于smart wait"""
email = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'email')),message=u'元素加载超时!')
email.send_keys("*** 你的账号 ***")
passwd = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'password')),message=u'元素加载超时!')
passwd.send_keys("*** 你的密码 ***")
wd.find_element_by_id("login").click() #点击登录except NoSuchElementException as e: print e.message
举报