`Traceback (most recent call last):
File "fmcrawler_sql.py", line 317, in <module>
crawl(initFighter=fighter,K=4)
File "fmcrawler_sql.py", line 114, in crawl
write_page_to_database(initFighterURL,cur)
File "fmcrawler_sql.py", line 292, in write_page_to_database
write_fights_to_database(fights,cur)
File "fmcrawler_sql.py", line 211, in write_fights_to_database
fightId = hash(bothFighters+fight['Event'])
TypeError: cannot concatenate 'str' and 'list' objects
`
这些线有什么问题?
答案 0 :(得分:0)
阅读TypeError
:你有一个字符串和列表......列表是显而易见的,所以你需要从列表中取出'Event'并与另一个变量连接 - 然后放回到名单。取决于你的需要。
>>> ['a']+['b']
['a', 'b']
>>> l = ['b']
>>> ['a' + l[0]]
['ab']
>>>
答案 1 :(得分:0)
无法真正了解您发布的内容,但此错误非常常见。在实际代码中的某处,您尝试连接(或添加)字符串和列表。问题出现在这里:
File "fmcrawler_sql.py", line 211, in write_fights_to_database
fightId = hash(bothFighters+fight['Event'])
TypeError: cannot concatenate 'str' and 'list' objects
我猜测bothFighters
是一个列表而fight['Event']
是一个字符串。将字符串更改为列表,错误可能会消失。 (Python允许您一起添加&#34;列表,使用两个列表的第一级条目创建更长的列表)。
如果您仍需要帮助,请使用您的代码进行更新。