qcc.py 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. from common.execptions import QccError
  2. from common.tools import html2element
  3. from crawler.download import Downloader
  4. class QccService(Downloader):
  5. def get_site(self, name: str):
  6. site = '-'
  7. headers = {
  8. "authority": "www.qcc.com",
  9. "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
  10. "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
  11. "cache-control": "no-cache",
  12. "pragma": "no-cache",
  13. "upgrade-insecure-requests": "1",
  14. "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
  15. }
  16. cookies = {
  17. "CNZZDATA1254842228": "1319079473-1648702017-https%253A%252F%252Fwww.google.com%252F%7C1650962497",
  18. }
  19. url = "https://www.qcc.com/web/search"
  20. params = {"key": name.strip()}
  21. response = self.get(url, headers=headers, cookies=cookies, params=params)
  22. if response.status_code != 200:
  23. raise QccError(reason='企查查搜索接口调用失败', code=response.status_code)
  24. element = html2element(response.text)
  25. nodes = element.xpath('//table[@class="ntable ntable-list"]//tr[1]/td[3]/div[1]/div[4]/div[2]/span[3]/span/child::*')
  26. if len(nodes) > 0:
  27. sub_node = nodes[0]
  28. site = "".join("".join(sub_node.xpath('./text()')).split())
  29. return site