我的例子
from bs4 import BeautifulSoup
import requests
result = requests.get("https://pythonprogramming.net/parsememcparseface/")
c = result.content
soup = BeautifulSoup(c,'lxml')
patch_name = soup.find_all(["a", "p"])
u = soup.get_text()
print(u)
如何获取我需要的文本,我可以将其存储在变量中供以后使用。
答案 0 :(得分:0)
这将返回a
和p
标记列表:
patch_name = soup.find_all(["a", "p"])
您可以获取列表的所有文本:
[tag.get_text() for tag in patch_name]