码迷,mamicode.com
首页 > Web开发 > 详细

selenium获取页面动态html;静态html

时间:2016-05-03 12:35:16      阅读:2210      评论:0      收藏:0      [点我收藏+]

标签:

 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(rC:\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)

 

selenium获取页面动态html;静态html

标签:

原文地址:http://www.cnblogs.com/oneby/p/5454428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!