Scrapy 调试代码

取自

Scrapy终端(Scrapy shell)

#判断 url是否是想要的

def parse(self, response):
    if ".org" in response.url:
        from scrapy.shell import inspect_response    #调试语句
        inspect_response(response, self)
>>> response.url
'http://example.org'

测试提取代码:

>>> sel.xpath('//h1[@class="fn"]')
[]

浏览器打开链接

>>> view(response)
True

最后您可以点击Ctrl-D(Windows下Ctrl-Z)来退出终端,恢复爬取:

>>> ^D2014-01-23 17:50:03-0400 [myspider] DEBUG: Crawled (200) <GET http://example.net> (referer: None)

在浏览器中打开URL

from scrapy.utils.response import open_in_browser
    def parse(self, response):
        if "item name" not in response.body:
            open_in_browser(response)


转载于:https://my.oschina.net/sii/blog/655856

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值