Ad

Scrapy + Python + Xpath : Datapoint Couldn't Be Scraped Always

- 1 answer

I want to scrape the address from this page:

http://calendar.youtoocanrun.com/events/chennai-1/kanchipuram-half-marathon-2018-3rd-edition/

enter image description here

When I am writing this xpath:

response.xpath('//span[@itemprop]/text()').extract()

I am getting desired result,i.e., a list containing the address elements:

[u'Chennai', u'Chennai', u'Tamil Nadu', u'India']

But when I am writing this xpath:

response.xpath('//div[@class="geodir_more_info post_address"]//span[@itemprop]/text()').extract()

I am getting an empty list.

Why?

Ad

Answer

Because there are two spaces between the div classes (geodir_more_info and post_address).

Input:

response.xpath('//div[@class="geodir_more_info  post_address"]/span[@itemprop]/text()').extract()

Output:

[u'Chennai', u'Chennai', u'Tamil Nadu', u'India']
Ad
source: stackoverflow.com
Ad