Update fetch.py

Give the user more info ,when error occurs
debug_branch
EnsignMK 2023-07-18 00:55:06 +02:00 committed by GitHub
parent 8cd21621f9
commit ba2b2468c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -9,15 +9,20 @@ from bs4 import BeautifulSoup
def fetchTags(ch):
if ch:
try:
if "danbooru.donmai.us/posts" not in ch:
return "unsupported url"
page = requests.get(ch)
page = requests.get(ch)
soup = BeautifulSoup(page.content, "html.parser")
soup = BeautifulSoup(page.content, "html.parser")
info = soup.findAll("a", class_="search-tag")
tags = [j.text for j in info]
info = soup.findAll("a", class_="search-tag")
tags = [j.text for j in info]
return ' ,'.join(tags)
return ' ,'.join(tags)
except Exception as err:
# most likely an bad url
return "Incomplete url OR unsupported url"
else:
return []