我正在尝试使用以下方法打印Python3字典:
b_result_page = []
b_result_list = []
b_result_page_and_list = {}
#b_result page contains urls like: somesite.com?first=11
for brp in b_result_page:
LIST_SELECT = '.b_algo'
for page_item_result in response.css(LIST_SELECT):
NAME_SELECT = 'h2 a ::attr(href)'
yield {
'name' : page_item_result.css(LIST_SELECT).extract(),
}
#b_result_page_and_list is an empty dict, and im trying to append several page_item_result to its key.
b_result_page_and_list.setdefault(brp, page_item_result)
for k,v in b_result_page:
print("key: {} value:{}\n".format(k, v))
当我尝试通过scrapy runspider scrape_b2.py
运行此操作时,出现错误:
for k,v in b_result_page:
ValueError: too many values to unpack (expected 2)
任何人都可以帮助我吗?
答案 0 :(得分:2)
两个问题:
您想循环遍历b_result_page_and_list
在字典上循环只会循环其键;你的意思是for k, v in b_result_page_and_list.items():
来获取键和值。