Selenium+PhantomJS(系列二:模拟登录淘宝)
Selenium+PhantomJS系列教程:
- Selenium+PhantomJS(系列一:设置User-Agent)
- Selenium+PhantomJS(系列二:模拟登录淘宝)
- Selenium+PhantomJS(系列三:模拟登录知乎)
- Selenium+PhantomJS(系列四:模拟登录微博)
- Selenium+PhantomJS(系列五:selenium的等待)
Selenium+PhantomJS(系列二:模拟登录淘宝)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from selenium import webdriver driver = webdriver.PhantomJS(executable_path='/opt/phantomjs-2.1.1-linux-i686/bin/phantomjs') driver.get(“https://login.taobao.com/member/login.jhtml“) driver.find_element_by_id("TPL_username_1").clear() driver.find_element_by_id("TPL_password_1").clear() driver.find_element_by_id("TPL_username_1").send_keys(self.username) driver.find_element_by_id("TPL_password_1").send_keys(self.password) driver.find_element_by_id("J_SubmitStatic").click() #driver.get_cookies()取得cookie cookie = "; ".join([item["name"] + "=" + item["value"] +"\n" for item in driver.get_cookies()]) print cookie #然后带上cookie登录后的页面去请求页面 |