请求模块Python文本格式

请求模块Python文本格式,python,python-3.x,python-requests,Python,Python 3.x,Python Requests,我使用python(.text)中的请求模块得到了一个类似于数据的响应,我现在可以将“数据”保存在变量中吗?是的,您正在寻找的是一个从您的请求中获得的HTML代码中提取文本的包 例如: print(html2text.html2text(“数据”)) 将打印: 资料 我建议解析文本 通常情况下,标签不仅仅是一个标签。您可以使用select()列出它们,然后使用for循环遍历它们。 导入请求 从bs4导入BeautifulSoup r = requests.get(url) soup = Be

我使用python(.text)中的请求模块得到了一个类似于
数据的响应,我现在可以将“数据”保存在变量中吗?

是的,您正在寻找的是一个从您的请求中获得的HTML代码中提取文本的包

例如:

print(html2text.html2text(“数据”))
将打印:

资料

我建议解析文本

通常情况下,标签不仅仅是一个标签。您可以使用select()列出它们,然后使用for循环遍历它们。 导入请求 从bs4导入BeautifulSoup

r = requests.get(url)

soup = BeautifulSoup(r.text, 'lxml')
atags = soup.select('a')
for text in atags:
    linktext = text.text
    # Do something with the text
r = requests.get(url)

soup = BeautifulSoup(r.text, 'lxml')
atag = soup.select_one('a')
text  = atag.text
# Do something with the text
但如果只是一个标签,您可以运行select\u one 导入请求 从bs4导入BeautifulSoup

r = requests.get(url)

soup = BeautifulSoup(r.text, 'lxml')
atags = soup.select('a')
for text in atags:
    linktext = text.text
    # Do something with the text
r = requests.get(url)

soup = BeautifulSoup(r.text, 'lxml')
atag = soup.select_one('a')
text  = atag.text
# Do something with the text

你能发布你的代码吗?