課程
/后端開發(fā)
/Python
/Python開發(fā)簡單爬蟲
如上需要賬號密碼登錄的網(wǎng)頁怎么實現(xiàn)Python抓取
2017-09-01
源自:Python開發(fā)簡單爬蟲 7-7
正在回答
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 Bywd = 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
舉報
本教程帶您解開python爬蟲這門神奇技術的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2017-09-02
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