user2492364
user2492364

Reputation: 6703

newbie in scrapy : how to response.css scrape the text part?

When I practice, I want to catch only the text part (1,2,3,4,5...), without the part how can I write the response.css("td[class='c1']")?

scrapy shell "https://tw.movies.yahoo.com/chart.html"
response.css("td[class='c1']")

enter image description here

Upvotes: 5

Views: 14967

Answers (1)

alecxe
alecxe

Reputation: 473893

Here are two options, one using css(), another one using xpath():

>>> response.css("td.c1 > span::text").extract()
[u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9', u'10', u'11', u'12', u'13', u'14', u'15', u'16', u'17', u'18', u'19', u'20']
>>> response.xpath("//td[@class='c1']/span/text()").extract()
[u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9', u'10', u'11', u'12', u'13', u'14', u'15', u'16', u'17', u'18', u'19', u'20']

Upvotes: 5

Related Questions