比如我们要调试某网页:https://g.widora.cn/

shell不依赖工程环境

scrapy shell https://g.widora.cn/

类似页面F12,可用对象都列出来了,一般常用response

前面省略

2020-05-08 21:07:18 [asyncio] DEBUG: Using selector: KqueueSelector
[s] Available Scrapy objects:
[s] scrapy scrapy module (contains scrapy.Request, scrapy.Selector, etc)
[s] crawler <scrapy.crawler.Crawler object at 0x1118626d0>
[s] item {}
[s] request <GET https://g.widora.cn/>
[s] response <200 https://g.widora.cn/>
[s] settings <scrapy.settings.Settings object at 0x111bd7890>
[s] spider <DefaultSpider 'default' at 0x112103250>
[s] Useful shortcuts:
[s] fetch(url[, redirect=True]) Fetch URL and update local objects (by default, redirects are followed)
[s] fetch(req) Fetch a scrapy.Request and update local objects
[s] shelp() Shell help (print this help)
[s] view(response) View response in a browser
2020-05-08 21:07:18 [asyncio] DEBUG: Using selector: KqueueSelector

查找某群号:xpath等支持re,extract、get等后面不支持re

In [1]: response.xpath("/html/body/div/div[5]/p/a").extract()                   

Out[1]: ['<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=f65cb90612db81ef9bee771440adb40c004933a18b7c0466a279486936aedc79" src="title=" style="color:#00a1d6">G.widora.cn 群(1031687050)</a>']

In [2]: response.xpath("/html/body/div/div[5]/p/a/text()").extract()            

Out[2]: ['G.widora.cn 群(1031687050)']

In [3]: response.xpath("/html/body/div/div[5]/p/a/text()")                      

Out[3]: [<Selector xpath='/html/body/div/div[5]/p/a/text()' data='G.widora.cn 群(1031687050)'>]

In [4]: response.xpath("/html/body/div/div[5]/p/a/text()").re('\d+')            

Out[4]: ['1031687050']

终端写这个很麻烦,还是在浏览器上先调试通过再写代码

【python爬虫】scrapy入门5--xpath等后面接正则的更多相关文章

  1. python爬虫Scrapy(一)-我爬了boss数据

    一.概述 学习python有一段时间了,最近了解了下Python的入门爬虫框架Scrapy,参考了文章Python爬虫框架Scrapy入门.本篇文章属于初学经验记录,比较简单,适合刚学习爬虫的小伙伴. ...

  2. python爬虫scrapy项目详解(关注、持续更新)

    python爬虫scrapy项目(一) 爬取目标:腾讯招聘网站(起始url:https://hr.tencent.com/position.php?keywords=&tid=0&st ...

  3. python爬虫scrapy框架——人工识别登录知乎倒立文字验证码和数字英文验证码(2)

    操作环境:python3 在上一文中python爬虫scrapy框架--人工识别知乎登录知乎倒立文字验证码和数字英文验证码(1)我们已经介绍了用Requests库来登录知乎,本文如果看不懂可以先看之前 ...

  4. python爬虫-基础入门-python爬虫突破封锁

    python爬虫-基础入门-python爬虫突破封锁 >> 相关概念 >> request概念:是从客户端向服务器发出请求,包括用户提交的信息及客户端的一些信息.客户端可通过H ...

  5. python爬虫-基础入门-爬取整个网站《3》

    python爬虫-基础入门-爬取整个网站<3> 描述: 前两章粗略的讲述了python2.python3爬取整个网站,这章节简单的记录一下python2.python3的区别 python ...

  6. python爬虫-基础入门-爬取整个网站《2》

    python爬虫-基础入门-爬取整个网站<2> 描述: 开场白已在<python爬虫-基础入门-爬取整个网站<1>>中描述过了,这里不在描述,只附上 python3 ...

  7. python爬虫-基础入门-爬取整个网站《1》

    python爬虫-基础入门-爬取整个网站<1> 描述: 使用环境:python2.7.15 ,开发工具:pycharm,现爬取一个网站页面(http://www.baidu.com)所有数 ...

  8. Python爬虫教程-22-lxml-etree和xpath配合使用

    Python爬虫教程-22-lxml-etree和xpath配合使用 lxml:python 的HTML/XML的解析器 官网文档:https://lxml.de/ 使用前,需要安装安 lxml 包 ...

  9. Python爬虫之lxml-etree和xpath的结合使用

    本篇文章给大家介绍的是Python爬虫之lxml-etree和xpath的结合使用(附案例),内容很详细,希望可以帮助到大家. lxml:python的HTML / XML的解析器 官网文档:http ...

  10. [Python爬虫] scrapy爬虫系列 <一>.安装及入门介绍

    前面介绍了很多Selenium基于自动测试的Python爬虫程序,主要利用它的xpath语句,通过分析网页DOM树结构进行爬取内容,同时可以结合Phantomjs模拟浏览器进行鼠标或键盘操作.但是,更 ...

随机推荐

  1. json序列化字符串后,配置枚举类型显示数值而不是名称

    2019独角兽企业重金招聘Python工程师标准>>> 经常有这么一个需求,实体类里面用到枚举常量,但序列化成json字符串时.默认并不是我想要的值,而是名称,如下 类 @Data ...

  2. du命令、df命令、磁盘分区

    df:汇报文件系统的磁盘使用空间[root@localhost ~]# df文件系统 1K-块 已用 可用 已用% 挂载点/dev/sda3 29140072 1022920 28117152 4% ...

  3. python(读取 excel 操作 xlrd 模块)

    一.安装 xlrd 模块 到 python 官网下载 http://pypi.python.org/pypi/xlrd 模块安装,前提是已经安装了 python 环境. 或者在 cmd 窗口  pip ...

  4. Haporxy

    安装Haproxy: 下载 wget https://fossies.org/linux/misc/haproxy-1.8.3.tar.gz tar -zxf haproxy-.tar.g cd ha ...

  5. ASP .NET Core 建立列表和表单View

    前几篇文章对控制器Controller以及布局页_Layout相关的代码与作用介绍了一下.接下来就是建立控制器对应的列表和对应的表单. 建立Department文件夹,在文件夹下面建立普通的Index ...

  6. 学习Vue第一节,Vue的模式与写法格式

    引用Vue <script src="js/vue-2.4.0.js" type="text/javascript" charset="utf- ...

  7. D. Misha, Grisha and Underground 树链剖分

    D. Misha, Grisha and Underground 这个题目算一个树链剖分的裸题,但是这个时间复杂度注意优化. 这个题目可以选择树剖+线段树,时间复杂度有点高,比较这个本身就有n*log ...

  8. 软路由OpenWrt(LEDE)2020.4.6编译 UnPnP+NAS+多拨+网盘+DNS优化

    近期更新:2020.04.06编译-基于OpenWrt R2020.3.19版本,源码截止2020.04.06.   2020.04.06更新记录: 以软件包形式提供ServerChan(微信推送) ...

  9. Battery Charging Specification Revision 1.2 中文版本

    Battery Charging Specification Revision 1.2 Li,Guanglei 2014.04.03 Rev0.1 转载请注明转自:http://blog.csdn.n ...

  10. docker redis shell

    docker中安装好redis后,运行 docker ps 指令,查看所有运行中的镜像信息 然后运行 docker inspect --format "{{ .State.Pid}}&quo ...