python模拟浏览器webdriver登陆网站后抓取页面并输出

关键在于以下两行代码 特别是find_element_by_xpath写法 很多写成 findElementsByXpath不知道是写错了 还是高级版本是这么写的...

#webElement = self.dr.find_element_by_xpath("//*");

#print(webElement.get_attribute("outerHTML"))

import os
from selenium import webdriver
import time

class Firefox_webdriver:
dr=webdriver.Chrome()

def autosend(self,my_username,my_password,interval,num):
self.dr.get("http://cas.baidu.com/?tpl=www2&fromu=http%3A%2F%2Fwww2.baidu.com%2F")
self.dr.implicitly_wait(1)
time.sleep(40)
#self.dr.find_element_by_id("TANGRAM__3__userName").send_keys("xxx@qq.com")
#self.dr.find_element_by_id("TANGRAM__3__password").send_keys("xxx")
#self.dr.find_element_by_name("pass-button pass-button-submit").click()
#self.dr.find_element_by_id("TANGRAM__3__submit").click()
#time.sleep(5)
self.dr.get("http://fengchao.baidu.com/nirvana/main.html?userid=5365496&%20%20userid=5365496&t=1397266614555&castk=62a4dmj7728a3a6aed231#/~pkgId=5&target=aoPk%20%20g")
time.sleep(30)
webElement = self.dr.find_element_by_xpath("//*");
print(webElement.get_attribute("outerHTML"))

'''for i in range(1,num):
url="http://test2.tieba.baidu.com/d/c/addPost?gid=258&content="+str(i)+"&sign=*****"
self.dr.get(url)
time.sleep(interval)
#self.dr.close()
'''
if __name__ == "__main__":
browser = Firefox_webdriver()
browser.autosend("*****","****",2,10)

上一篇:第14.7节 Python模拟浏览器访问实现http报文体压缩传输


下一篇:ansible 配置运行环境