我想抓取一個站點118.69.35.146/sjc/來測試SCRAPY框架。我用HTMLXPathSelector選擇,詳情如下任務的代碼片段:如何在Scrapy中使用HtmlXpathSelector在</td>之間獲取數據?
def parse(self, response):
sel = HtmlXPathSelector(response)
sites = sel.select('//table[@id="grv_GiaVangUpdate"]/tr')
items = []
for site in sites:
item = FinanceItem()
item['buy'] = site.select('//td[3]/text()').extract()
item['sell'] = site.select('//td[4]/text()').extract()
items.append(item)
return items
我希望得到的文本數據值和。
但是JSON文件輸出的結果我剛剛得到了總共16個節點的空值。
[{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []},
{"sell": [], "buy": []}]
請問這裏的任何專家爲我檢查這段代碼,教我哪一點我錯了。
在此先感謝!