noam76

Untitled

May 9th, 2023
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. import scrapy
  2. import openpyxl
  3.  
  4. class SolarKeyMarkSpider(scrapy.Spider):
  5.     name = "solarkeymark_spider"
  6.     start_urls = ["https://solarkeymark.eu/database/"]
  7.  
  8.     def parse(self, response):
  9.         wb = openpyxl.Workbook()
  10.         ws = wb.active
  11.         ws.append(["Company Name", "Brand", "License Number", "η0", "b", "a1", "a2", "a3"])
  12.  
  13.         for row in response.xpath('//table[@id="Table1"]//tr'):
  14.             tds = row.xpath('.//td')
  15.             if len(tds) == 8:
  16.                 company_name = tds[0].xpath('./text()').get().strip()
  17.                 brand = tds[1].xpath('./text()').get().strip()
  18.                 license_number = tds[2].xpath('./text()').get().strip()
  19.                 η0 = tds[3].xpath('./text()').get().strip()
  20.                 b = tds[4].xpath('./text()').get().strip()
  21.                 a1 = tds[5].xpath('./text()').get().strip()
  22.                 a2 = tds[6].xpath('./text()').get().strip()
  23.                 a3 = tds[7].xpath('./text()').get().strip()
  24.  
  25.                 ws.append([company_name, brand, license_number, η0, b, a1, a2, a3])
  26.  
  27.         wb.save("solarkeymark_results.xlsx")
  28.  
Advertisement
Add Comment
Please, Sign In to add comment