cra LinkExtractor中的意外符号

进取心

我正在研究Scrapy库,并尝试制作一个小爬虫。

这是搜寻器的规则:

rules = (
    Rule(LinkExtractor(restrict_xpaths='//div[@class="wrapper"]/div[last()]/a[@class="pagenav"][last()]')),
    # Rule(LinkExtractor(restrict_xpaths='//span[@class="update_title"]/a'), callback='parse_item'),
)

但我收到此错误消息:

DEBUG: Crawled (200) <GET http://web/category.php?id=4&> (referer: None)
DEBUG: Crawled (404) <GET http://web/%0D%0Acategory.php?id=4&page=2&s=d> (referer: http://web/category.php?id=4&)
DEBUG: Ignoring response <404 http://web/%0D%0Acategory.php?id=4&page=2&s=d>: HTTP status code is not handled or not allowed

这是html的样子:

<a class="pagenav" href=" category.php?id=4&page=8&s=d& ">8</a>
|
<a class="pagenav" href=" category.php?id=4&page=9&s=d& ">9</a>
|
<a class="pagenav" href=" category.php?id=4&page=10&s=d& ">10</a>
|         
<a class="pagenav" href=" category.php?id=4&page=2&s=d& ">Next ></a>

有人可以解释%0D%0A的来源吗?亲切的问候,马克西姆。

UPD:我做了一个简单的功能

def process_value(value):
    value = value.strip()
    print value
    return value

并将规则更改为

rules = (
    Rule(LinkExtractor(restrict_xpaths='//div[@class="wrapper"]/div[last()]/a[@class="pagenav"][last()]', process_value=process_value)),
    # Rule(LinkExtractor(restrict_xpaths='//span[@class="update_title"]/a'), callback='parse_item'),
)

print命令将打印以下内容:

Crawled (200) <GET http://web/category.php?id=4&>(referer: None)
http://web/
category.php?id=4&page=2&s=d&
Crawled (404) <GET http://web/%0D%0Acategory.php?%0D=&id=4&page=2&s=d>(referer: http://web/category.php?id=4&)
维亚克·卡科夫斯基

%0D%0AHTML编码中的CRLF字符。

您解析的网站的作者将字符放入HTML文档中。我认为,有时是因为它们在IDE或浏览器中不可见。

解释不可见字符的含义:

以及有关编码的更多信息http://www.w3schools.com/tags/ref_urlencode.asp

我建议您以这种方式剥离所有需要获取的链接:

href = href.strip()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章