xigua.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import requests
  2. import execjs
  3. import re
  4. class xigua:
  5. def __init__(self, url):
  6. self.url = url
  7. if "wid_try=1" not in self.url:
  8. self.url = self.url + "&wid_try=1"
  9. self.headers = {
  10. "referer": self.url,
  11. "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36",
  12. }
  13. self.nonce = self.getNonce()
  14. def getNonce(self):
  15. res = requests.get(self.url, headers=self.headers)
  16. return res.cookies.get("__ac_nonce")
  17. def getSign(self):
  18. jscode = execjs.compile(open("./js/xigua.js").read())
  19. ctx = jscode.call("getSign", self.nonce, self.url)
  20. return f"__ac_nonce={self.nonce};__ac_signature={ctx};__ac_referer={self.url}"
  21. def start(self):
  22. self.headers.update({"cookie": self.getSign()})
  23. html = requests.get(self.url, headers=self.headers)
  24. res = re.findall("window._SSR_HYDRATED_DATA=(.*?)</script>", html.text)[0].replace("undefined", 'null')
  25. print(res)
  26. return res
  27. if __name__ == '__main__':
  28. xigua().start()