Fix infinite redirect issue

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-08-21 15:21:43 -04:00
parent 34e7febb82
commit cdb9c3ecd5
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
1 changed files with 5 additions and 7 deletions

12
main.py
View File

@ -5,19 +5,17 @@ import requests
import html import html
import re import re
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from urllib.parse import quote, unquote
def scrape(url): def scrape(url):
data = requests.get(url) data = requests.get(url)
our_path = re.sub(r".*://.*/", "/", request.url) our_path = re.sub(r".*://.*/", "/", request.url)
path = re.sub(r".*://.*/", "/", data.url) path = re.sub(r".*://.*/", "/", data.url)
print() if our_path != path and \
print(our_path) quote(unquote(re.sub("[?&=]", "", our_path))) != re.sub("[?&=]", "", path):
print(path) # this is bad ^
print() return f"REDIRECT {path}"
if our_path != path:
return f"REDIRECT {path}"
ret = [] ret = []
soup = BeautifulSoup(data.text, "html.parser") soup = BeautifulSoup(data.text, "html.parser")
for div in soup.find_all("div"): for div in soup.find_all("div"):