博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于PhantomJS的网页抓取及写入文件
阅读量:6860 次
发布时间:2019-06-26

本文共 878 字,大约阅读时间需要 2 分钟。

# coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilities if __name__=="__main__":    url = "http://XXX.XXXXX.com/XX.html"    dcap = dict(DesiredCapabilities.PHANTOMJS)    dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 ")        obj = webdriver.PhantomJS(executable_path=r'D:\phantomjs\bin\phantomjs.exe',desired_capabilities=dcap)    obj.get(url)    html = obj.page_source    obj.quit()        fw = open("D:\\test.html","w",encoding='utf-8')    fw.write(html)    fw.close()    #     cx = sqlite3.connect("D:\SQLite\chuangbing.db")#     cx.execute("insert into page_html (page_time,page_url,page_resource) values (datetime('now'),?,?)",(url,html))#     cx.commit()#     cx.close()

 

转载于:https://www.cnblogs.com/wpcnblog/p/8443009.html

你可能感兴趣的文章
JVM系列二:GC策略&内存申请、对象衰老
查看>>
MySQL 数据库备份策略:全备与增量备份
查看>>
Springboot的热部署
查看>>
Thinking in UML-1-为什么需要UML
查看>>
vs编译obj给delphi用
查看>>
过游戏保护NP或TP的几种方法和思路
查看>>
equals和hashcode为什么要一起重写
查看>>
模态与非模态对话框的问题
查看>>
httpclient 备注 控制连接时间及多线程错误
查看>>
地对地导弹地对地导弹地对地导弹
查看>>
浏览器根对象window之performance
查看>>
让div 充满整个body
查看>>
常用排序算法
查看>>
程序员保持快乐活跃的6个好习惯(转)
查看>>
找工作的一些感悟——前端小菜的成长
查看>>
jSON Call can throw but it is not marked with try
查看>>
基于bootstrap的jQuery多级列表树插件 treeview
查看>>
node06
查看>>
笔试题[转]
查看>>
图片轮换
查看>>