mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
Optimize Search Function to be way faster
This commit is contained in:
@@ -11,21 +11,14 @@ def scrape_uztracker():
|
|||||||
print(search_url)
|
print(search_url)
|
||||||
try:
|
try:
|
||||||
response = requests.get(search_url)
|
response = requests.get(search_url)
|
||||||
|
response.raise_for_status()
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
links = soup.find_all('a')
|
links = soup.find_all('a', class_="genmed tLink", href=lambda x: x and x.startswith('./viewtopic'))
|
||||||
found_links = False
|
|
||||||
for link in links:
|
for link in links:
|
||||||
if link.has_attr('href'):
|
if link.b:
|
||||||
href = link['href']
|
print("Result found:", link.b.text, "|", link['href'])
|
||||||
global post_url
|
else:
|
||||||
post_url = f"https:{href}" if isinstance(href, str) and href.startswith("//") else href
|
print("No Results found.")
|
||||||
if isinstance(post_url, str) and post_url.startswith("./viewtopic.php?t="):
|
|
||||||
post_url = f"https://uztracker.net{post_url[1:]}"
|
|
||||||
# print(f"Found post link: {post_url}")
|
|
||||||
found_links = True
|
|
||||||
get_post_title(post_url)
|
|
||||||
if not found_links:
|
|
||||||
print(f"No post link found on {search_url}")
|
|
||||||
return soup
|
return soup
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
print(f"Failed to fetch {search_url}: {e}")
|
print(f"Failed to fetch {search_url}: {e}")
|
||||||
@@ -59,8 +52,9 @@ def get_magnet_link(post_url="https://uztracker.net/viewtopic.php?t=23897"):
|
|||||||
# and - if x exists, THEN check the next part
|
# and - if x exists, THEN check the next part
|
||||||
# x.startswith('magnet:') - does x start with "magnet:"?
|
# x.startswith('magnet:') - does x start with "magnet:"?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
soup = scrape_uztracker()
|
soup = scrape_uztracker()
|
||||||
if soup:
|
|
||||||
get_magnet_link()
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user