scrapy爬虫【D】3 实战 - scrapy爬虫抓取京东图书

一、测试

  1. 打开京东图书
  2. 在console中输入$('ul.gl-warp > li').length,结果为30,说明该页面是js动态页面
  3. 输入document.getElementsByClassName('page')[0].scrollIntoView(true),可以完成拖拽动作
    注释:获取类名为 page 的元素,见【说明】
  4. span#J_resCount::text获取id属性为J_resCount的span标签的文本
    span.J_resCount::text获取class属性为J_resCount的span标签的文本

二、参考


scrapy爬取京东商城某一类商品的信息和评论(一)
scrapy爬取京东商城某一类商品的信息和评论(二)

三、流程

  1. 打开docker,开启splash端口
    sudo service docker start
    sudo docker run -p 8050:8050 scrapinghub/splash

Linux 中遇到的BUG

  1. 一切准备就绪,运行爬虫,出现Telnet console listening on 127.0.0.1:6024
    问题:

win10 中的BUG


1、找不到splash模块 No module named ‘splash’(已解决)

  • 描述:装好scrapy-splash后,依旧无法运行爬虫,并报错
  • 原因:没有安装splash
  • 解决办法:安装splash,打开端口,运行爬虫
1. 下载splash包 `pip install scrapy-splash`
2. 官网下载docker `https://store.docker.com/editions/community/docker-ce-desktop-windows`
3. 利用docker 运行splash  'docker run -p 8050:8050 scrapinghub/splash'
4. 验证splash是否打开,网页输入'http://localhost:8050'
4. 编辑scrapy

参考:scrapy-splash爬取JS生成的动态页面
参考:Windows Docker 安装

2、报错 ModuleNotFoundError: No module named ‘twisted.enterprise”(已解决)

  • 描述:
    安装完docker、splash后,运行爬虫报错,并且原先能正常运行的爬虫也出现同样错误

  • 怀疑1:安装包损坏,得重装scrapy
    操作:重新安装scrapy后,没用

  • 怀疑2:但运行不带from twisted.enterprise import adbapi的爬虫没问题,而且以前这条命令能执行,但现在不能执行,怀疑twisted需要升级
    操作:升级twisted ,conda upgrade twisted,问题解决

3、运行爬虫出现 ImportError: cannot import name ‘_win32stdio’

  • 描述:
    更新splash pip install -- upgrade splash,运行爬虫出现ImportError: cannot import name '_win32stdio'

参考:Scrapy在Python3下报错:“cannot import name ‘_win32stdio’”解决办法

4、运行quotes爬虫,报错 ModuleNotFoundError: No module named ‘splash.downloadermiddlewares’

  • windows解决不了了,换linux了。。

猜你喜欢

转载自blog.csdn.net/qq_41682050/article/details/81334120
今日推荐