首页 > Web开发 > 详细

scrapy使用PhantomJS和selenium爬取数据

时间:2018-07-30 18:32:44      阅读:202      评论:0      收藏:0      [点我收藏+]

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爬取数据

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!