import urllib.request import re import time url =…
- User
import urllib.request import re import time
def f(): try: # Add a User-Agent to the HTTP request headers headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'} request = urllib.request.Request(url, headers=headers) response = urllib.request.urlopen(request) html = response.read().decode('utf-8')
code# Extract formhash using regex formhash_match = re.search(r'name="formhash" value="(.+?)"', html) if not formhash_match: raise ValueError("formhash not found.") formhash = formhash_match.group(1) # Extract codehash using regex codehash_match = re.search(r'id="seccode_(.+?)"', html) if not codehash_match: raise ValueError("codehash not found.") codehash = codehash_match.group(1) # Construct CAPTCHA image URL urlimg = f'https://www.3swg.com/misc.php?mod=seccode&action=update&idhash={codehash}&0.7910379078247034&modid=undefined' request_img = urllib.request.Request(urlimg, headers=headers) img_html = urllib.request.urlopen(request_img).read().decode('utf-8') codeurl_match = re.findall(r'src="(.+?)"', img_html) if len(codeurl_match) < 2: # Ensure we captured enough data raise ValueError("CAPTCHA image URL not found.") codeurl = 'https://www.3swg.com/' + codeurl_match[1] # Download CAPTCHA image urllib.request.urlretrieve(codeurl, 'misc.png') print("Downloaded CAPTCHA image as 'misc.png'.") print("formhash:", formhash) print("codehash:", codehash) print("CAPTCHA URL:", codeurl) except Exception as e: print("An error occurred:", e) - Assistant
- User
把下载图片,变成ac.txt
- Assistant
- User
图片变成a.txt
- Assistant