2

I am running a scrapy project. I need to extract a content within a tag attribute like this:

<meta itemprop="datePublished" content="2018-07-08">

In this case would be the date within the content attribute. So far I was only able to extract content in the midle of tags.

thanks!

Rodrigo
  • 137
  • 2
  • 8

2 Answers2

3

Check this out ->

response.css("time::attr(title)").extract()

Reference ->

https://www.analyticsvidhya.com/blog/2017/07/web-scraping-in-python-using-scrapy/

EDIT

In your case code should be ->

response.css("meta::attr(content)").extract()

Thanks

Utkarsh Dubey
  • 703
  • 11
  • 31
3

Here is XPath way:

content = response.xpath('//meta[@itemprop="datePublished"]/@content').extract_first()
gangabass
  • 10,607
  • 2
  • 23
  • 35