scrapy + selenium 爬取js生成的网页元素

本文介绍了如何结合Scrapy和Selenium爬取JavaScript动态生成的网页内容。首先,安装Python 2.7,接着安装Scrapy,解决安装中可能出现的扩展问题。然后安装Selenium,下载并运行Selenium服务器。创建Scrapy工程,并参考相关教程实现动态网页抓取。在过程中可能会遇到如Socket错误和FirefoxProfile异常,可以参考相关StackOverflow解答和GitHub示例代码进行解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、安装python (我用的是2.7版本的)

2、安装scrapy:   详情请参考 http://blog.csdn.net/wukaibo1986/article/details/8167590 (提示,能下载源码安装的就避免用pip install **)

     安装过程中遇到python扩展问题”unable to find vcvarsall.bat“的解决办法: http://blog.csdn.net/ren911/article/details/6448696

3、安装selenium,  https://pypi.python.org/pypi/selenium, 注意安装后Download the server separately, from: http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.0.jar,  然后运行(命令行运行,需要安装Java Runtime Environment (JRE))  java -jar selenium-server-standalone-2.42.0.jar

4、建scrapy工程  , 参考 http://www.searchtb.com/2011/01/an-introduction-to-crawler.html?spm=0.0.0.0.HrlxVl

5、scrapy和selenium结合抓取动态网页:  https://github.com/tmslav/google_adwords_scrape/blob/master/adwords_bot.py

7、Python Selenium socket error - [Errno 61] Connection refused:  http://stackoverflow.com/questions/12913991/python-selenium-socket-error-errno-61-connection-refused

8、Selenium: FirefoxProfile exception Can't load the profile: https://github.com/tmslav/google_adwords_scrape/blob/master/adwords_bot.py

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值