0

我打开scrapy shell如下

scrapy shell "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/"

这给了我:

[s] Available Scrapy objects:
[s]   hxs        <HtmlXPathSelector xpath=None data=u'<html><head><meta http-equiv="Content-Ty'>
[s]   item       {}
[s]   request    <GET http://www.dmoz.org/Computers/Programming/Languages/Python/Books/>
[s]   response   <200 http://www.dmoz.org/Computers/Programming/Languages/Python/Books/>
[s]   settings   <CrawlerSettings module=None>
[s]   spider     <BaseSpider 'default' at 0x9e1d3ec>
[s] Useful shortcuts:
[s]   shelp()           Shell help (print this help)
[s]   fetch(req_or_url) Fetch request (or URL) and update local objects
[s]   view(response)    View response in a browser


In [1]: hxs.select('//title')
Out[1]: [<HtmlXPathSelector xpath='//title' data=u'<title>Open Directory - Computers: Progr'>]

响应的标题与预期的一样:

In [1]: hxs.select('//title')
Out[1]: [<HtmlXPathSelector xpath='//title' data=u'<title>Open Directory - Computers: Progr'>]

现在我用一个简单的 fetch 来跟进:

In [2]: fetch("http://www.google.com")

shell 输出表明对象已更新:

In [2]: fetch("http://www.google.com")
2013-10-18 23:10:09+0530 [default] DEBUG: Redirecting (302) to <GET http://www.google.co.in/?gws_rd=cr&ei=eHJhUo2sOobSrQeM5ICAAg> from <GET http://www.google.com>
2013-10-18 23:10:09+0530 [default] DEBUG: Crawled (200) <GET http://www.google.co.in/?gws_rd=cr&ei=eHJhUo2sOobSrQeM5ICAAg> (referer: None)
[s] Available Scrapy objects:
[s]   hxs        <HtmlXPathSelector xpath=None data=u'<html itemscope="" itemtype="http://sche'>
[s]   item       {}
[s]   request    <GET http://www.google.com>
[s]   response   <200 http://www.google.co.in/?gws_rd=cr&ei=eHJhUo2sOobSrQeM5ICAAg>
[s]   settings   <CrawlerSettings module=None>
[s]   spider     <BaseSpider 'default' at 0x9e1d3ec>
[s] Useful shortcuts:
[s]   shelp()           Shell help (print this help)
[s]   fetch(req_or_url) Fetch request (or URL) and update local objects
[s]   view(response)    View response in a browser

但是,我发现他们没有。view(response) 显示 dmoz 页面

并提取标题给出相同的旧标题:

In [3]: hxs.select('//title')
Out[3]: [<HtmlXPathSelector xpath='//title' data=u'<title>Open Directory - Computers: Progr'>]

我在这里想念什么?

谢谢!

4

1 回答 1

1

即使它对我有用,也可能与此错误有关:https ://github.com/scrapy/scrapy/issues/396

您可以尝试运行最新的开发版本吗?

更新:问题来自 ipython 0.10,更新到最新版本,它应该可以按预期工作。它也在scrapy 0.19+(最新开发)中得到修复。所以你可以升级 ipython 或 scrapy。

于 2013-10-19T01:27:54.587 回答