【问题标题】:'builtin_function_or_method' object is not iterable - What is wrong with my second For loop?'builtin_function_or_method' 对象不可迭代 - 我的第二个 For 循环有什么问题?
【发布时间】:2019-10-03 05:04:27
【问题描述】:

为什么会出现类型错误?

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)

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

【问题讨论】:

  • 你想要.values()而不是.values
  • 您需要使用values() 调用该函数@在@MikeManieri 下方查看我的答案:)

标签: python csv beautifulsoup request


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2011-04-23
    相关资源
    最近更新 更多