from http.server import HTTPServer, BaseHTTPRequestHandler import requests def read_book(resp): i = 1 for item in resp.decode().split(','): print(str(i) + ": " + item) open("{:04d}.jpg".format(i), 'wb').write(requests.get(item).content) i += 1 print("done... you probably want to run sth like: \"convert *.jpg out.pdf\"") class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_POST(self): content_length = int(self.headers['Content-Length']) body = self.rfile.read(content_length) self.send_response(204) self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() # print(body) read_book(body) def do_OPTIONS(self): print(self.headers) self.send_response(204) self.send_header('Access-Control-Allow-Origin', '*') self.send_header('Access-Control-Allow-Method', 'POST, GET, OPTIONS') self.send_header('Access-Control-Allow-Headers', 'content-type') self.end_headers() print("starting service ...") print("If you have a book from \"www.pearson-studium.de/drm/reader/nu/code/\" open the developer console on this site and paste the following:") print("xhr = new XMLHttpRequest(); xhr.open('POST', \"http://localhost:8000\"); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(p.content.list);") httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler) httpd.serve_forever()