1 # -*- coding: utf-8 -*- 2 from selenium import webdriver 3 import sys 4 import urllib2 5 import time 6 import codecs 7 reload(sys) 8 sys.setdefaultencoding(‘utf-8‘) 9 10 def gethtml(url): 11 page = urllib2.urlopen(url) 12 html_all = page.read() 13 return html_all 14 15 def get_jingtai_dongtai_html(url): 16 fp=webdriver.FirefoxProfile(r‘C:\Users\j\AppData\Roaming\Mozilla\Firefox\Profiles\pn4ffyp2.default‘) 17 sel = webdriver.Firefox(fp) 18 sel.get(url) 19 time.sleep(3) 20 sel.set_window_size(480, 600) 21 html1=sel.page_source 22 with codecs.open(‘result-dongtai4.html‘,‘w‘,encoding=‘utf-8‘)as putin1: 23 putin1.write(html1) 24 html2=gethtml(url) 25 with codecs.open(‘result-jingtai4.html‘,‘w‘,encoding=‘utf-8‘)as putin2: 26 putin2.write(html2) 27 sel.close() 28 sel.quit() 29 url="http://patent.ip1840.com/faming/186246.html" 30 get_jingtai_dongtai_html(url)
时间: 2024-10-06 10:53:45