scrapy table

Solutions on MaxInterview for scrapy table by the best coders in the world

showing results for - "scrapy table"
Mirko
15 Aug 2016
1import scrapy
2 
3 
4class ScrapeTableSpider(scrapy.Spider):
5    name = 'scrape-table'
6    allowed_domains = ['https://getbootstrap.com/docs/4.0/content/tables']
7    start_urls = ['http://https://getbootstrap.com/docs/4.0/content/tables/']
8 
9 
10    def start_requests(self):
11        urls = [
12            'https://getbootstrap.com/docs/4.0/content/tables',
13        ]
14        for url in urls:
15            yield scrapy.Request(url=url, callback=self.parse)
16 
17    def parse(self, response):
18        for row in response.xpath('//*[@class="table table-striped"]//tbody/tr'):
19            yield {
20                'first' : row.xpath('td[1]//text()').extract_first(),
21                'last': row.xpath('td[2]//text()').extract_first(),
22                'handle' : row.xpath('td[3]//text()').extract_first(),
23            }