简体   繁体   中英

Xpath is correct but Scrapy doesn't work

I'm trying to download two fields from a webpage, I identify the XPath expressions for each one and then run the spider, but nothing is downloaded.

The webpage: http://www.morningstar.es/es/funds/snapshot/snapshot.aspx?id=F0GBR04MZH

The field I want to itemize is ISIN .

The spider runs without errors, but the output is empty.

Here is the line code:

item['ISIN'] = response.xpath('//*[@id="overviewQuickstatsDiv"]/table/tbody/tr[5]/td[3]/text()').extract()

Try to remove tbody from XPath:

'//*[@id="overviewQuickstatsDiv"]/table//tr[5]/td[3]/text()'

Note that this tag is added by your browser while page rendering and it's absent in page source

PS I suggest you to use IMHO even better XPath:

'//td[.="ISIN"]/following-sibling::td[contains(@class, "text")]/text()'

I think response.selector was not given. Try this.

response.selector.xpath('//*[@id="overviewQuickstatsDiv"]/table/tbody/tr[5]/td[3]/text()').extract()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM