Python selenium模拟浏览器


#! /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)









 
 

猜你喜欢

转载自blog.csdn.net/Clannad_niu/article/details/79344234