Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scrapy
- from openpyxl import Workbook
- class SolkeySpider(scrapy.Spider):
- name = 'solkey_spider'
- start_urls = ['https://www.duurzaamloket.nl/SolKey_X014/index.php?SchemeNo=0&Offset=1&SearchText=&PageCnt=500']
- def parse(self, response):
- table = response.css('.LicDetails')
- headers = table.css('th::text').getall()
- rows = table.css('tr')[1:]
- wb = Workbook()
- ws = wb.active
- # Write headers to the first row
- for col_num, header in enumerate(headers, 1):
- ws.cell(row=1, column=col_num, value=header)
- # Write table data to the worksheet
- for row_num, row in enumerate(rows, 2):
- cols = row.css('td::text').getall()
- for col_num, col in enumerate(cols, 1):
- ws.cell(row=row_num, column=col_num, value=col.strip())
- # Save the workbook to an Excel file
- wb.save('solkey_data.xlsx')
Advertisement
Add Comment
Please, Sign In to add comment