我有多个文本文件,这些文件用于存储网站的源页面。所以每个文本文件都是一个源页面。读取保存在文本文件中的源文件并提取文本
我需要使用下面的代码保存在文本文件中一个div类提取文本:
from bs4 import BeautifulSoup
soup = BeautifulSoup(open("zing.internet.accelerator.plus.txt"))
txt = soup.find('div' , attrs = { 'class' : 'id-app-orig-desc' }).text
print txt
我已经检查了我的汤对象的类型,以确保它不使用字符串find方法,同时寻找为div类。 类型汤对象的
print type(soup)
<class 'bs4.BeautifulSoup'>
我已经从一个the previous post所取出的参考,并书面beautifulsoup语句内公开声明。
错误:从页面
Traceback (most recent call last):
File "html_desc_cleaning.py", line 13, in <module>
txt2 = soup.find('div' , attrs = { 'class' : 'id-app-orig-desc' }).text
AttributeError: 'NoneType' object has no attribute 'text'
来源:
请勿上传图片添加文字,因为图片无用 – styvane