python phantomjs+ selenium2 抓取动态js网页(版本python2.7+)
2016-05-19 11:40
555 查看
1、下载phantomjs linux版本
解压即可单独使用方法:../bin/phantomjs create_img.js xxx.com(可选)
示例,抓取网页截图:
建立一个pageload.js文件
编写以下js
var page = require('webpage').create(); page.open('http://cuiqingcai.com', function (status) { console.log("Status: " + status); if (status === "success") { page.render('example.png'); } phantom.exit(); });
运行
phantomjs pageload.js
会在当前目录下看到截图
2、pip安装selenium
pip install selenium3、selenium+phantomjs 结合写python文件
#!/usr/bin/python #encoding:utf-8 from selenium import webdriver #写phantomjs执行文件地址 driver = webdriver.PhantomJS(executable_path='/usr/local/soft_download/python_file/phantomjs/bin/phantomjs') driver.get("http://mofangdata.cn/") #driver.find_element_by_id('search_form_input_homepage').send_keys("Nirvana") #driver.find_element_by_id("search_button_homepage").click() print driver.current_url driver.quit()注意给python 执行权限 chmod u+x 文件名
运行 ./xx.py
相关文章推荐
- python dict与json转换
- BeaufulSoup获取特定标签下内容的方法
- python SQLAlchemy操作mysql数据库:插入,查询,删除,更新
- python SQLAlchemy创建mysql数据库连接
- Python 进阶——重访 list (二)
- Python3 迭代器与生成器
- python中schedule模块的使用
- python 解析 json文件
- Python中逗号的三种作用
- python BeautifulSoup
- Python中装饰器
- 数据科学部门如何使用Python和R组合完成任务
- python开发目录合并小工具 PathMerge
- Python 资源大全中文版
- python2.7下同步华为云照片的爬虫程序实现
- Python之路【第二十三篇】爬虫
- python memoryview
- selenium+python笔记3
- Python:模块(一)
- 如何在命令行模式下查看Python帮助文档---dir、help、__doc__