BeautifulSoup 获取 a标签里的文本内容

上传:sinat_40317 浏览: 17 推荐: 0 文件:PDF 大小:60.13KB 上传时间:2020-12-31 00:22:57 版权申诉
说明 想要获取 a标签里的单词如下所示。 代码 from bs4 import BeautifulSoup f = open("word.txt", "r") # 设置文件对象 html = f.read() # 将txt文件的所有内容读入到字符串html中 soup = BeautifulSoup(html, 'lxml') # 获取a标签里的文本内容 for item in soup.find_all("a"): print(item.string) # 将单词写入five_star.txt 文件 with open('five_star.txt', 'a',
上传资源
用户评论