zoukankan      html  css  js  c++  java
  • selenium加载本地配置文件 ; 获取页面动态html ; 静态html

     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:UsersjAppDataRoamingMozillaFirefoxProfilespn4ffyp2.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)
  • 相关阅读:
    C语言博客I作业04
    C语言I博客作业03
    C语言I博客作业02
    C语言ll作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
  • 原文地址:https://www.cnblogs.com/oneby/p/5454428.html
Copyright © 2011-2022 走看看