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

scrapy使用PhantomJS和selenium爬取数据

时间:2018-07-30 18:39:08      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:rap   drive   htm   ide   lin   load   col   数据   使用   

1.phantomjs 安装

下载:http://phantomjs.org/download.html

解压:

tar  -jxvf  phantomjs-2.1.1-linux-x86_64.tar.bz2

重命名:

mv /usr/local/phantomjs-2.1.1-linux-x86_64/ /usr/local/phantomjs

软连接:

ln -s /usr/local/phantomjs/bin/phantomjs /usr/bin/ 

[root@izuf622gt8apcfsz7i1mqdz /]# phantomjs
phantomjs>

2.selenium 安装

pip 安装: pip install selenium

使用:

    def process_request(self, request, spider):
        driver = webdriver.PhantomJS()
        # driver = webdriver.Chrome()
        driver.get(request.url)
        body = driver.page_source
        input_first  = driver.find_element_by_id(stockID_)
        input_first.clear()

        input_first.send_keys(000150)

        button = driver.find_element_by_id(button)
        dataClick = button.click()
        print(dataClick)
        body = driver.page_source
        # driver.switch_to.frame(‘i_nr‘)
        # print("访问:", driver.page_source)
        return HtmlResponse(driver.current_url, body=body, encoding=utf-8)

 

scrapy使用PhantomJS和selenium爬取数据

标签:rap   drive   htm   ide   lin   load   col   数据   使用   

原文地址:https://www.cnblogs.com/myvic/p/9392079.html

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