Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,17 +27,16 @@ def my_custom_tool(arg1:str)-> str: #it's import to specify the return type
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
response = requests.get(url, headers=headers)
|
| 30 |
-
response.raise_for_status()
|
| 31 |
soup = BeautifulSoup(response.content, "html.parser")
|
| 32 |
results = soup.find_all("li", class_="booklink")
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
link = result.find("a", class_="link")
|
| 36 |
if link:
|
| 37 |
full_url = "https://www.gutenberg.org" + link["href"]
|
| 38 |
-
|
| 39 |
-
return
|
| 40 |
-
|
| 41 |
except requests.exceptions.RequestException as e:
|
| 42 |
print(f"Error: {e}")
|
| 43 |
return None
|
|
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
response = requests.get(url, headers=headers)
|
| 30 |
+
response.raise_for_status()
|
| 31 |
soup = BeautifulSoup(response.content, "html.parser")
|
| 32 |
results = soup.find_all("li", class_="booklink")
|
| 33 |
+
if results: #Check if results are present.
|
| 34 |
+
link = results[0].find("a", class_="link") #Grabs the first result
|
|
|
|
| 35 |
if link:
|
| 36 |
full_url = "https://www.gutenberg.org" + link["href"]
|
| 37 |
+
return full_url
|
| 38 |
+
return None #Return None if no results, or no link.
|
| 39 |
+
|
| 40 |
except requests.exceptions.RequestException as e:
|
| 41 |
print(f"Error: {e}")
|
| 42 |
return None
|