Веб-сайт: https://orionstars.vip:8781/
Код:
Код: Выделить всё
from bs4 import BeautifulSoup
import requests
url = "https://orionstars.vip:8781/default.aspx"
base_url = "https://orionstars.vip:8781/"
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Cookie": "", # Replace with the actual session ID if dynamic
"Host": "orionstars.vip:8781",
"Pragma": "no-cache",
"Referer": url,
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0",
"sec-ch-ua": '"Microsoft Edge";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"'
}
session = requests.Session()
response = session.get(url, headers=headers)
if response.status_code != 200:
print(f"Invalid Status code: {response.status_code}")
exit()
headers["Cookie"] = f'ASP.NET_SessionId={session.cookies["ASP.NET_SessionId"]}'
soup = BeautifulSoup(response.content, features="lxml", parser="html.parser")
captcha_image = base_url + soup.find(name="img", attrs={"id": "ImageCheck"}).get("src")
response = requests.get(captcha_image, headers=headers)
if response.status_code == 200:
with open("captcha_image.png", "wb") as file:
file.write(response.content)
Код: Выделить всё
requests==2.30.0, beautifulsoup4==4.12.3, lxml==5.3.0
Подробнее здесь: https://stackoverflow.com/questions/790 ... image-each