forbes.py 703 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python3
  2. import requests
  3. import json
  4. def parse(link):
  5. s_r = requests.session()
  6. print_link=link+"/print/"
  7. cookie = {'toURL':link,'refURL':'','referrer':''}
  8. result = s_r.get(print_link, cookies=cookie)
  9. out = result.content.decode("utf-8")
  10. out = out.split("\n")
  11. ret = {'title':"", 'body': ""}
  12. for l in out:
  13. if "fbs_settings.content = {" in l:
  14. substr=l.split("=",1)[1]
  15. substr="".join(substr.rsplit(";",1))
  16. try:
  17. ret = json.loads(substr)
  18. except:
  19. pass
  20. return "<html><head><title>%s</title></head><body><article>%s</article></body></html>" %(ret["title"], ret["body"] )