动态网站爬虫Python-selenium-PhantomJS

from selenium import webdriver
#from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
    "Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20"
)###设置浏览器hearders

obj = webdriver.PhantomJS(executable_path="E:/phantomjs/bin/phantomjs.exe",desired_capabilities=dcap)

proxy=webdriver.Proxy()
proxy.proxy_type=ProxyType.MANUAL
proxy.http_proxy=‘115.211.50.97:8118‘
proxy.add_to_capabilities(webdriver.DesiredCapabilities.PHANTOMJS)
obj.start_session(webdriver.DesiredCapabilities.PHANTOMJS)

obj.maximize_window()
obj.get(‘http://fz12345.fuzhou.gov.cn/callcenter/callSearchDo.do‘)
obj.set_page_load_timeout(15)  #等待时间
obj.find_element_by_xpath("/html/body/div[2]/div/div[1]/div[5]/div[2]/div[2]/form/div[3]/ul/li[5]/a").click()

a=obj.find_element_by_xpath("/html/body/div[2]/div/div[1]/div[5]/div[2]/div[2]/form/div[2]/table/tbody/tr[3]").text
print(a)
obj.close()
时间: 2024-08-21 16:54:11

动态网站爬虫Python-selenium-PhantomJS的相关文章

python --selenium+phantomjs爬取动态页面广告源码

背景:利用爬虫,爬取网站页面广告元素,监控爬取元素的数目,定时发送监控邮件 #!/usr/bin/env python2.7 # -*- coding: utf-8 -*- ''' @xiayun @[email protected] #爬取网站内容,利用phantomjs:IP代理+修改UA+动态页面执行JS ''' from selenium import webdriver from selenium.webdriver.common.desired_capabilities import

python+selenium+PhantomJS爬取网页动态加载内容

一般我们使用python的第三方库requests及框架scrapy来爬取网上的资源,但是设计javascript渲染的页面却不能抓取,此时,我们使用web自动化测试化工具Selenium+无界面浏览器PhantomJS来抓取javascript渲染的页面,下面实现一个简单的爬取 环境搭建 准备工具:python3.5,selenium,phantomjs 我的电脑里面已经装好了python3.5 安装Selenium pip3 install selenium 安装Phantomjs 按照系统

Python爬虫小白---(二)爬虫基础--Selenium PhantomJS

一.前言   前段时间尝试爬取了网易云音乐的歌曲,这次打算爬取QQ音乐的歌曲信息.网易云音乐歌曲列表是通过iframe展示的,可以借助Selenium获取到iframe的页面元素, 而QQ音乐采用的是异步加载的方式,套路不一样,这是主流的页面加载方式,爬取有点难度,不过也是对自己的一个挑战. 二.Python爬取QQ音乐单曲 之前看的慕课网的一个视频, 很好地讲解了一般编写爬虫的步骤,我们也按这个来. 爬虫步骤 1.确定目标 首先我们要明确目标,本次爬取的是QQ音乐歌手刘德华的单曲. (百度百科

Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容

在上一篇python使用xslt提取网页数据中,要提取的内容是直接从网页的source code里拿到的. 但是对于一些Ajax或动态html, 很多时候要提取的内容是在source code找不到的,这种情况就要想办法把异步或动态加载的内容提取出来. python中可以使用selenium执行javascript,selenium可以让浏览器自动加载页面,获取需要的数据.selenium自己不带浏览器,可以使用第三方浏览器如Firefox, Chrome等,也可以使用headless浏览器如P

Windows下 Python Selenium PhantomJS 抓取网页并截图

安装Python https://www.python.org/downloads/release 下载安装 将Python目录加入PATH 安装SetupTools https://pypi.Python.org/pypi/setuptools 下载解压到Python目录并进入 cmd执行Python setup.py install 安装Pip https://pypi.Python.org/pypi/setuptools 下载解压到Python目录并进入 cmd执行Python setup

python+selenium+phantomjs爬百度美女图片

#conding:utf-8 import unittest from selenium import webdriver from urllib.request import * import re import time from bs4 import BeautifulSoup #测试类 class baidupic(unittest.TestCase): #初始化测试 def setUp(self): self.dv = webdriver.PhantomJS() #测试方法 def t

python selenium+phantomJS自动化测试环境

0x00配置phantomJS 1. 在windows平台下 此种方法是弹浏览器进行自动化测试的. 1.下载谷歌的驱动 https://chromedriver.storage.googleapis.com/index.html 2.将解压后的chromedriver.exe放到chrome浏览器的安装目录下. 3.在代码中调用浏览器驱动,执行自动化操作. chromedriver = 'chromedriver绝对路径' driver = webdriver.Chrome(chromedriv

python爬虫 selenium+phantomjs动态解析网页,加载页面成功,返回空数据

废话不多说,直接说重点: 刚开始做的时候,代理IP,头部信息池,都已经做好了,使用selenium+phantomjs获取js动态加载后的源码 起初挺好的,能出来动态加载后的源码,但是运行了几次之后,电脑有点卡顿(估计是运存太小),源码就获取不到了,返回的数据 都是空数据,以至于都是出错 在做的时候一定要给页面加载之前做一个延时,以保证页面的正常加载出来,这样我们才能获取导数据 我在加载前后都做了延时等待,当然,我这个就是说这个意思,没必要仿照 可以根据自己的需求进行设置,然后源码就加载出来了,

[Python爬虫] 之二十六:Selenium +phantomjs 利用 pyquery抓取智能电视网站图片信息

一.介绍 本例子用Selenium +phantomjs爬取智能电视网站(http://www.tvhome.com/news/)的资讯信息,输入给定关键字抓取图片信息. 给定关键字:数字:融合:电视 二.网站信息 三.数据抓取 针对上面的网站信息,来进行抓取 1.首先抓取信息列表 抓取代码:Elements = doc('div[class="main_left fl"]').find('div[class="content"]').find('ul').find