Python ';内置函数或方法';对象不可编辑-我的第二个For循环有什么问题?
为什么这里会出现打字错误Python ';内置函数或方法';对象不可编辑-我的第二个For循环有什么问题?,python,csv,beautifulsoup,request,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
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)
我需要能够访问现在作为值存储在listitems中的链接您需要使用
listitems.values()
而不是listitems.values来迭代字典中的值,因为您无法迭代内置函数,这就是您看到的错误
for b in listitems.values():
newpage = requests.get("URL.com"+b)
您需要.values()
而不是.values
您需要使用values()
在@MikeManieri:)下面检查我的答案