您的位置:首页 > 编程语言 > Python开发

Python selenium模拟浏览器

2018-02-21 21:30 447 查看
#! /usr/bin/env python
#coding:utf-8

from selenium import webdriver
import sys
import time

def get_html():
obj = webdriver.PhantomJS()
obj.set_page_load_timeout(5)
try:
obj.get('http://10.10.28.189/web/guest/cn/websys/jobList/jobListGetHistory.cgi')
try:
obj.find_element_by_class_name("defaultTableCommandButton").click()
except Exception as e:
print e
text = obj.page_source
obj.quit()
return text
except Exception as e:
print e
return ''

def save_file(data):
with open('Ricoh_Aficio_MP_301.html', 'w') as f:
f.write(str(data))

def main():
data = get_html()
save_file(data)

if __name__ == '__main__':
reload(sys)
sys.setdefaultencoding('utf-8')
#while True:
main()
#time.sleep(30*60)


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Python selenium