import urllib.request import urllib.parse import http.client import re import time from datetime import datetime from urllib.parse import urlparse GET_URL = "https://www.pornhub.org/random" POST_URL = "https://ebinlauta.net/api/post/create/" # ------------------------- # GET request # ------------------------- def get_page(url, headers=None): if headers is None: headers = {} req = urllib.request.Request(url, headers=headers) with urllib.request.urlopen(req) as res: return res.read().decode("utf-8", errors="ignore") # ------------------------- # POST request # ------------------------- def post_data(url, data, headers=None): if headers is None: headers = {} parsed = urlparse(url) conn = http.client.HTTPSConnection(parsed.hostname) conn.request( "POST", parsed.path, body=data, headers=headers ) res = conn.getresponse() body = res.read().decode("utf-8", errors="ignore") return res.status, body # ------------------------- # Extract comment (regex) # ------------------------- def extract_comment(html): match = re.search( r'
\s*([\s\S]*?)', html ) return match.group(1).strip() if match else None # ------------------------- # Main job # ------------------------- def run_job(): try: print("\nRunning job at:", datetime.now().strftime("%Y-%m-%d %H:%M:%S")) headers = { "User-Agent": "Mozilla/5.0", "Cookie": "accessAgeDisclaimerPH=2" } # 1. GET page html = get_page(GET_URL, headers) # 2. Extract comment message = extract_comment(html) if not message: print("No comment found") return print("Extracted:", message) # 3. POST data post_body = urllib.parse.urlencode({ "message": message, "board": "int" }).encode("utf-8") post_headers = { "User-Agent": "Mozilla/5.0", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": str(len(post_body)) } status, response = post_data(POST_URL, post_body, post_headers) print("POST status:", status) print("Done.") except Exception as e: print("Error:", str(e)) # ------------------------- # Run once immediately # ------------------------- run_job() # ------------------------- # Run every 5 minutes # ------------------------- while True: time.sleep(1 * 60) run_job()