为什么它不让我将列表转换为字符串?
Why isn't it letting me convert a list into a string?
我正在使用 BeautifulSoup
抓取维基百科信息框并尝试将其导出到 table
我想将我的列表转换成 BeatifulSoup 以便能够使用 .find_all
和 .find
来查找嵌套标签,但是因为我没有在网上找到任何可以转换的东西,我决定把它转换成字符串,然后尝试把字符串转换成漂亮的汤
当我尝试 .join
我的字符串时出现错误:
TypeError: sequence item 0: expected str instance, Tag found.
我也试过了
print (u'').join(unicode(row1) for fow1 in link)
print (u'').join(row1.stripped_strings)
但是这些给出了错误
AttributeError: 'NoneType' object has no attribute '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. 它是一个函数。在Python 2中也是如此 如果你使用from __future__ import print_function
Try
print(''.join(str(row1) for fow1 in link))
我正在使用 BeautifulSoup
抓取维基百科信息框并尝试将其导出到 table
我想将我的列表转换成 BeatifulSoup 以便能够使用 .find_all
和 .find
来查找嵌套标签,但是因为我没有在网上找到任何可以转换的东西,我决定把它转换成字符串,然后尝试把字符串转换成漂亮的汤
当我尝试 .join
我的字符串时出现错误:
TypeError: sequence item 0: expected str instance, Tag found.
我也试过了
print (u'').join(unicode(row1) for fow1 in link)
print (u'').join(row1.stripped_strings)
但是这些给出了错误
AttributeError: 'NoneType' object has no attribute '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. 它是一个函数。在Python 2中也是如此 如果你使用from __future__ import print_function
Try
print(''.join(str(row1) for fow1 in link))