“ builtin_function_or_method”对象不可迭代-我的第二个For循环出了什么问题?

时间:2019-05-16 01:51:30

标签: python csv beautifulsoup request

为什么我在这里遇到类型错误?

import csv

import requests
page = requests.get("URL.com")


from bs4 import BeautifulSoup
soup = BeautifulSoup(page.content, 'html.parser')

listitems = {}
for a in soup.select('a.sitemaplink', href=True):
    listitems.update({a.text:a['href']})


for b in listitems.values:
    newpage = requests.get("URL.com"+b)

我需要能够访问现在作为值存储在列表项中的链接

1 个答案:

答案 0 :(得分:0)

您需要使用listitems.values()而不是listitems.values对字典的值进行迭代,因为您无法对内置函数进行迭代,这就是您所看到的错误

for b in listitems.values():
    newpage = requests.get("URL.com"+b)