Spaces:
Sleeping
Sleeping
Update tools/visit_webpage.py
Browse files- tools/visit_webpage.py +13 -7
tools/visit_webpage.py
CHANGED
@@ -24,14 +24,20 @@ class VisitWebpageTool(Tool):
|
|
24 |
) from e
|
25 |
try:
|
26 |
# Send a GET request to the URL with a 20-second timeout
|
27 |
-
req = Request(
|
28 |
-
|
29 |
-
|
30 |
-
)
|
31 |
-
response = urlopen(req).read()
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
#response = requests.get(url, timeout=20)
|
34 |
-
|
35 |
|
36 |
# Convert the HTML content to Markdown
|
37 |
markdown_content = markdownify(response.text).strip()
|
|
|
24 |
) from e
|
25 |
try:
|
26 |
# Send a GET request to the URL with a 20-second timeout
|
27 |
+
# req = Request(
|
28 |
+
# url=url,
|
29 |
+
# headers={'User-Agent': 'Mozilla/5.0'}
|
30 |
+
# )
|
31 |
+
# response = urlopen(req).read().decode('utf-8')
|
32 |
+
# print(response)
|
33 |
+
headers = {
|
34 |
+
'User-Agent': 'Mozilla/5.0'
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
response = requests.get(url, headers=headers, timeout=20)
|
39 |
#response = requests.get(url, timeout=20)
|
40 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
41 |
|
42 |
# Convert the HTML content to Markdown
|
43 |
markdown_content = markdownify(response.text).strip()
|