g
This commit is contained in:
parent
e4c4c93a1f
commit
b8ea79408c
2 changed files with 6 additions and 17 deletions
|
@ -370,29 +370,18 @@ def edit_post(pid, v):
|
|||
def get_post_title(v):
|
||||
|
||||
url = request.values.get("url", None)
|
||||
if not url:
|
||||
return abort(400)
|
||||
if not url: return abort(400)
|
||||
|
||||
#mimic chrome browser agent
|
||||
headers = {"User-Agent": f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"}
|
||||
try:
|
||||
x = requests.get(url, headers=headers)
|
||||
except BaseException:
|
||||
return {"error": "Could not reach page"}, 400
|
||||
|
||||
|
||||
if not x.status_code == 200:
|
||||
return {"error": f"Page returned {x.status_code}"}, x.status_code
|
||||
try: x = requests.get(url, headers=headers)
|
||||
except BaseException: return {"error": "Could not reach page"}, 400
|
||||
|
||||
if not x.status_code == 200: return {"error": f"Page returned {x.status_code}"}, x.status_code
|
||||
|
||||
try:
|
||||
soup = BeautifulSoup(x.content, 'html.parser')
|
||||
|
||||
data = {"url": url,
|
||||
"title": soup.find('title').string
|
||||
}
|
||||
|
||||
return data
|
||||
return {"url": url, "title": soup.find('title').string}
|
||||
except BaseException:
|
||||
return {"error": f"Could not find a title"}, 400
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue