-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch.py
38 lines (32 loc) · 1006 Bytes
/
fetch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
from bs4 import BeautifulSoup
def fetch_content(url: str):
"""
从指定的URL中获取内容
"""
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
# 寻找包含特定文本的<p>标签
p_tag = soup.select_one("body > main > div > section > div.border-r10 > p:nth-of-type(1)")
if p_tag:
return p_tag.text
else:
return ""
def format_content(processed_text: str, url: str):
"""
格式化内容
"""
question = f"Act as a summarizer. Please summarize {url}. The following is the content:\n\n{processed_text}"
return question
def fetch(url: str):
"""
从指定的URL中提取内容并生成问题
"""
try:
content = fetch_content(url)
question = format_content(content, url)
return question
except:
return f"Please say \"Sorry, I couldn't fetch the url {url}\""
if __name__ == "__main__":
fetch("https://dev.qweather.com/en/help")