仅限 Scrapy returns 第一个结果
Scrapy only returns first result
我正在尝试抓取 here 的预格式化 html。
但是我的代码只有 returns 1 个价格而不是所有 10 个价格。
在这里看到的代码:
class MySpider(BaseSpider):
name = "working1"
allowed_domains = ["steamcommunity.com"]
start_urls = ["http://steamcommunity.com/market/search/render/?query=&appid=440"]
def parse(self, response):
sel = Selector(response)
price = sel.xpath("//text()[contains(.,'$')]").extract()[0].replace('\r\n\t\t\t\r\n\t\t\t','')
print price
我是 scrapy/xpath 的超级新手,所以我不太确定为什么它不打印价格的每个实例。
有什么建议吗?谢谢!
您正在获取 xpath 匹配的第一个结果。相反,遍历所有这些:
for price in sel.xpath("//text()[contains(., '$')]").extract():
print price.strip(r"\r\n\t")
打印([=12=].03
出现多次):
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
我正在尝试抓取 here 的预格式化 html。 但是我的代码只有 returns 1 个价格而不是所有 10 个价格。
在这里看到的代码:
class MySpider(BaseSpider):
name = "working1"
allowed_domains = ["steamcommunity.com"]
start_urls = ["http://steamcommunity.com/market/search/render/?query=&appid=440"]
def parse(self, response):
sel = Selector(response)
price = sel.xpath("//text()[contains(.,'$')]").extract()[0].replace('\r\n\t\t\t\r\n\t\t\t','')
print price
我是 scrapy/xpath 的超级新手,所以我不太确定为什么它不打印价格的每个实例。
有什么建议吗?谢谢!
您正在获取 xpath 匹配的第一个结果。相反,遍历所有这些:
for price in sel.xpath("//text()[contains(., '$')]").extract():
print price.strip(r"\r\n\t")
打印([=12=].03
出现多次):
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03
[=11=].03