Home > Blockchain >  How to get html tag attribute with square brackets using css selector?
How to get html tag attribute with square brackets using css selector?

Time:06-26

So I want to parse one page and it has several items with following structure:

<span itemprop="telephone" [class]="revealtel?'':'invisible'" >11111111</span>
<span itemprop="telephone" [class]="revealmainfax?'':'invisible'" >222222222</span>

I am using Scrapy and CSS selectors to parse data. But I cannot understand how to get tel or fax numbers. Itemprop is the same in both cases, so it cannot be used. So, how to select element with [class]="revealtel?'':'invisible' or [class]="revealmainfax?'':'invisible' attributes? Maybe not using CSS Selectors, but Xpath? I am not strong with Xpaths though...

Thanks in advance for helping me :)

CodePudding user response:

Using xpath to get a list of all text from elements with telephone as itemprop.

numbers = response.xpath('//span[@itemprop="telephone"]/text()').getall()

CodePudding user response:

Try:

response.css('span[itemprop="telephone"]::text').getall()
  • Related