分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

【爬虫】大杀器——phantomJS+selenium

发布时间:2023-09-06 01:55责任编辑:林大明关键词:selenium爬虫

【爬虫】大杀器——phantomJS+selenium

视频地址

江湖上有一个传说,得倚天屠龙者可称霸武林。爬虫中也有两个大杀器,他们结合在一起时,无往不利,不管你静态网站还是动态网站,通吃。

phantomJS

http://phantomjs.org/ 
一种无头浏览器,何为无头浏览器,你可以看做一个无界面的浏览器,电脑能看到,人却看不到(没界面怎么看)。 
下载安装:http://phantomjs.org/download.html

selenium

http://selenium-python.readthedocs.io/getting-started.html 
能直接调用浏览器(打开浏览器,访问某个页面,获取页面信息等)。 
安装命令:

  1. pip install selenium

phantomJS + selenium

phantomJS和selenium结合在一起就好像撼地神牛配上了跳刀、UG配上了辉耀、钢背兽配上了玲珑心。碰到搞不定的网站,直接上这两个大杀器。

举个例子

http://www.tianyancha.com/search/%E7%99%BE%E5%BA%A6%20%E6%9D%8E%E5%BD%A6%E5%AE%8F?checkFrom=searchBox 
天眼查为了反爬虫可谓是煞费苦心,还专门招聘反爬虫工程师,真是丧心病狂 

天眼查爬虫 python3

    1. from bs4 import BeautifulSoup
    2. from selenium import webdriver
    3. import urllib
    4. driver = webdriver.PhantomJS(
    5. ???executable_path=‘/usr/local/bin/phantomjs‘) ?# 浏览器的地址 如果是windows,应该是某个exe地址
    6. def search(keyword):
    7. ???url_keyword = urllib.parse.quote(keyword)
    8. ???url = "http://www.tianyancha.com/search/" + url_keyword + "?checkFrom=searchBox"
    9. ???print(url)
    10. ???driver.get(url)
    11. ???bsObj = BeautifulSoup(driver.page_source, "html5lib")
    12. ???print(bsObj)
    13. ???company_list = bsObj.find_all("span", attrs={"ng-bind-html": "node.name | trustHtml"})
    14. ???for company in company_list:
    15. ???????print(company.get_text())
    16. if __name__ == ‘__main__‘:
    17. ???search("阿里巴巴 马云")

【爬虫】大杀器——phantomJS+selenium

原文地址:https://www.cnblogs.com/pscc/p/9065144.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved