我怎样才能在我的蜘蛛内部获取一些 URL 以通过 HtmlXPathSelector 从页面中提取某些内容?但是 URL 是我想在代码中作为字符串提供的东西,而不是要遵循的链接。
我试过这样的事情:
req = urllib2.Request('http://www.example.com/' + some_string + '/')
req.add_header('User-Agent', 'Mozilla/5.0')
response = urllib2.urlopen(req)
hxs = HtmlXPathSelector(response)
但此时它会引发异常:
[Failure instance: Traceback: <type 'exceptions.AttributeError'>: addinfourl instance has no attribute 'encoding'