fork(1) download
  1. # -*- coding: utf-8 -*-
  2.  
  3. import requests
  4. from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
  5. from BeautifulSoup import BeautifulSoup
  6.  
  7. class HttpProcessor(BaseHTTPRequestHandler):
  8. def do_GET(self):
  9. req = requests.get("http://h...content-available-to-author-only...r.ru%s" % self.path)
  10.  
  11. self.send_response(req.status_code)
  12. self.send_header('content-type',req.headers['content-type'])
  13. self.end_headers()
  14. self.wfile.write(self.retranslate_page(req.text.encode('utf-8')))
  15.  
  16. def retranslate_page(self, page):
  17. soup = BeautifulSoup(page)
  18. div_content = soup.findAll("div", {"class": "content html_format"})
  19. """
  20. тут (div_content) твой ебучий контент, куда надо вуяривать тм'ки
  21. может разобрать его с помощью того же soup, а можешь
  22. ебаться в жёпу с бомжами, мне все равно
  23. """
  24. return page # заглушка, отдает страницу как есть, без тм'ок
  25.  
  26. serv = HTTPServer(("localhost", 80), HttpProcessor)
  27. serv.serve_forever()
Runtime error #stdin #stdout #stderr 1.08s 24624KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
Traceback (most recent call last):
  File "prog.py", line 5, in <module>
ImportError: No module named BeautifulSoup