我正在使用BeautifulSoup
抓取Wikipedia信息框,并尝试将其导出到表中
我想将列表转换为BeatifulSoup,以便能够使用.find_all
和.find
来查找嵌套标签,但是由于我没有在线找到任何要转换的内容,因此我决定将其转换为字符串然后尝试将字符串转换成漂亮的汤
当我尝试.join
我的字符串时,出现错误:
TypeError:序列项0:预期的str实例,找到了标记。
我也尝试过
print (u'').join(unicode(row1) for fow1 in link)
print (u'').join(row1.stripped_strings)
但是这些给了错误
AttributeError:'NoneType'对象没有属性'join'
my_table = soup.find('table',{'class':'infobox vcard'})
records = []
for my_tables in my_table:
row1 = my_table.find_all('th',{'scope':'row'})
print (row1)
print()
row2 = my_table.find_all('span')
print (row2)
html = ''.join(row1)
它应该将列表转换成字符串
最佳答案
print
不再是Python 3中的语句。它是一个函数。如果您使用from __future__ import print_function
Try,在Python 2中也是如此。
print(''.join(str(row1) for fow1 in link))
关于python - 为什么不让我将列表转换为字符串?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53993026/