Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 美丽的苏式hicup on unique<;td>;标签_Python_Beautifulsoup - Fatal编程技术网

Python 美丽的苏式hicup on unique<;td>;标签

Python 美丽的苏式hicup on unique<;td>;标签,python,beautifulsoup,Python,Beautifulsoup,我试图解析一个表,除了第5项之外,没有问题。项目似乎 有更精细的参数 我有点不明白为什么会这样 我的密码是: for row in tables.findAll('tr'): col = row.findAll('td') record =[] for i in range(0,9): cell = col[i].string.strip() 加上“汤”: 从: 如果标记包含多个内容,则不清楚.string应该引用什么,因此.string被定义为None

我试图解析一个表,除了第5项之外,没有问题。项目似乎 有更精细的参数

我有点不明白为什么会这样

我的密码是:

for row in tables.findAll('tr'):
    col = row.findAll('td')
    record =[]
    for i in range(0,9):
        cell = col[i].string.strip()
加上“汤”:

从:

如果标记包含多个内容,则不清楚.string应该引用什么,因此.string被定义为None

第五个
td
元素包含多个内容(一些文本和一个
img
),因此
string
属性为None

您可以使用
strings
stripped\u strings
生成器来提取此内容-在这种情况下,您只有一个返回值,但值得考虑如何处理
img
后面还有文本的情况

如果标签中有不止一个东西,您仍然可以只查看字符串。使用.strings生成器

这些字符串往往有很多额外的空格,您可以使用.stripped_strings生成器来删除这些空格


或者,将拉出纯文本内容,并为您提供一些控制文本剥离和连接的选项。

非常好的解释!
<td align="left" class="table-top">Item1</td>
<td align="left" class="table-top">Item2</td>
<td align="left" class="table-top">Item3</td>
<td align="center" class="table-top">Item4</td>
<td align="right" class="table-top">Item5 <img align="top" alt="" border="0" height="12" src="gfx/chart_hover_icon.gif" width="15"/></td>
cell = col[i].string.strip()
AttributeError: 'NoneType' object has no attribute 'strip'