Python 2.7 在带有约束的Scrapy中生成开始URL列表
我需要用Scrapy(房地产代理的广告)解析如下URL 无论url中使用的最小/最大价格是多少,服务器的响应限制为200个结果(请参阅url中的pxmin/pxman) 因此,我想使用一个函数,为具有正确价格带的start_URL生成URL,这样它就不会超过200个搜索结果,并且URL的价格范围为[0:1000000] 该函数将执行以下操作:Python 2.7 在带有约束的Scrapy中生成开始URL列表,python-2.7,scrapy,Python 2.7,Scrapy,我需要用Scrapy(房地产代理的广告)解析如下URL 无论url中使用的最小/最大价格是多少,服务器的响应限制为200个结果(请参阅url中的pxmin/pxman) 因此,我想使用一个函数,为具有正确价格带的start_URL生成URL,这样它就不会超过200个搜索结果,并且URL的价格范围为[0:1000000] 该函数将执行以下操作: 以第一个URL为例 检查结果数(“XML响应中的nbTrouvees”标记) 如果结果>200,则调整价格带;如果结果>链接http://ws.selo
- 以第一个URL为例
- 检查结果数(“XML响应中的nbTrouvees”标记)
- 如果结果>200,则调整价格带;如果结果<200,则添加到起始URL列表
- 函数增加价格带,直到价格达到1000000
- 函数返回最终开始URL列表,该列表将覆盖给定区域的所有属性
>>链接http://ws.seloger.com/search.xml? idq=124412901247&ci=830137&idqfix=1&pxmin=30000&pxmax=60000&idtt=2&SEARCHpg=1&getDtCreationMax=1&tri=d_dt_crea'
>>>xxs=XmlXPathSelector(响应(链接))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/Users/Gilles/workspace/Immo-Lab/lib/python2.7/site-packages/scrapy/selector/lxmlsel.py”,第31行,在__
_root=LxmlDocument(响应,self.\u解析器)
文件“/Users/Gilles/workspace/Immo-Lab/lib/python2.7/site-packages/scrapy/selector/lxmldocument.py”,第27行,新__
缓存[分析器]=\u工厂(响应,分析器)
文件“/Users/Gilles/workspace/Immo-Lab/lib/python2.7/site-packages/scrapy/selector/lxmldocument.py”,第13行,在工厂中
body=response.body作为unicode().strip().encode('utf8')或''
AttributeError:“Response”对象没有属性“body\u as\u unicode”
有什么想法吗?(仅供参考,它与我的蜘蛛一起工作)
多谢各位
Gilles我对此有了更多的想法。我认为最简单的方法是通过spider本身的列表理解来计算价格范围。我将不得不硬编码的增量将根据不同的价格范围。我可能得先做一些分布分析!
http://ws.seloger.com/search.xml?idq=?&cp=72&idqfix=1&pxmin=30000&pxmax=60000&idtt=2&SEARCHpg=1&getDtCreationMax=1&tri=d_dt_crea
>>>link = 'http://ws.seloger.com/search.xml? idq=1244,1290,1247&ci=830137&idqfix=1&pxmin=30000&pxmax=60000&idtt=2&SEARCHpg=1&getDtCreationMax=1&tri=d_dt_crea'
>>>xxs = XmlXPathSelector(Response(link))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Gilles/workspace/Immo-Lab/lib/python2.7/site- packages/scrapy/selector/lxmlsel.py", line 31, in __init__
_root = LxmlDocument(response, self._parser)
File "/Users/Gilles/workspace/Immo-Lab/lib/python2.7/site- packages/scrapy/selector/lxmldocument.py", line 27, in __new__
cache[parser] = _factory(response, parser)
File "/Users/Gilles/workspace/Immo-Lab/lib/python2.7/site- packages/scrapy/selector/lxmldocument.py", line 13, in _factory
body = response.body_as_unicode().strip().encode('utf8') or '<html/>'
AttributeError: 'Response' object has no attribute 'body_as_unicode'