# -*- coding: utf-8 -*-
import requests
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from BeautifulSoup import BeautifulSoup
class HttpProcessor(BaseHTTPRequestHandler):
def do_GET(self):
req = requests.get("http://h...content-available-to-author-only...r.ru%s" % self.path)
self.send_response(req.status_code)
self.send_header('content-type',req.headers['content-type'])
self.end_headers()
self.wfile.write(self.retranslate_page(req.text.encode('utf-8')))
def retranslate_page(self, page):
soup = BeautifulSoup(page)
div_content = soup.findAll("div", {"class": "content html_format"})
"""
тут (div_content) твой ебучий контент, куда надо вуяривать тм'ки
может разобрать его с помощью того же soup, а можешь
ебаться в жёпу с бомжами, мне все равно
"""
return page # заглушка, отдает страницу как есть, без тм'ок
serv = HTTPServer(("localhost", 80), HttpProcessor)
serv.serve_forever()
IyAtKi0gY29kaW5nOiB1dGYtOCAtKi0KCmltcG9ydCByZXF1ZXN0cwpmcm9tIEJhc2VIVFRQU2VydmVyIGltcG9ydCBCYXNlSFRUUFJlcXVlc3RIYW5kbGVyLCBIVFRQU2VydmVyCmZyb20gQmVhdXRpZnVsU291cCBpbXBvcnQgQmVhdXRpZnVsU291cCAKCmNsYXNzIEh0dHBQcm9jZXNzb3IoQmFzZUhUVFBSZXF1ZXN0SGFuZGxlcik6CglkZWYgZG9fR0VUKHNlbGYpOgoJCXJlcSA9IHJlcXVlc3RzLmdldCgiaHR0cDovL2guLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnIucnUlcyIgJSBzZWxmLnBhdGgpCgoJCXNlbGYuc2VuZF9yZXNwb25zZShyZXEuc3RhdHVzX2NvZGUpCgkJc2VsZi5zZW5kX2hlYWRlcignY29udGVudC10eXBlJyxyZXEuaGVhZGVyc1snY29udGVudC10eXBlJ10pCgkJc2VsZi5lbmRfaGVhZGVycygpCgkJc2VsZi53ZmlsZS53cml0ZShzZWxmLnJldHJhbnNsYXRlX3BhZ2UocmVxLnRleHQuZW5jb2RlKCd1dGYtOCcpKSkKCglkZWYgcm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