使用selenium+phantomjs模拟登录淘宝

使用自动化工具selenium可以很方便模拟淘宝登录


from selenium import webdriver
driver = webdriver.PhantomJS(executable_path='/opt/phantomjs-2.1.1-linux-i686/bin/phantomjs')
#driver = webdriver.Firefox()
               

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登录后的页面去请求页面



关于selenium和phantomjs的内容可以看(python解析js)selenium结合phantomjs抓取js生成的页面

你可能感兴趣的:(python,scrapy)