给定的参数太多(预期为 2 个)但字典元组最多有 2 个值
Too many arguments given (expected 2) but dictionary tuple has a max of 2 values
urllib.request.urlretrieve(src,path)
行给出了一个异常(给定的参数太多(预期 2)),但我从字典中获取这些值,其中元组具有所有 2 个值。我往南去哪里?
这是代码:
page_soup = soup(text, "lxml")
friends_div=page_soup.find("div",{"class":"j83agx80 btwxx1t3 lhclo0ds i1fnvgqd"})
img=friends_div.findAll("img")
users={}
for image in img:
if image.parent.has_key('href'):
parent=image.parent.parent.parent
users[(parent.select("span")[1].text)]= image['src']
opener = urllib.request.build_opener()
opener.addheaders=[('Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
urllib.request.install_opener(opener)
usersrc=""
filename=""
print(max(len(item) for item in users.items()))
for user ,src in users.items():
path=f"C:\Users\Krist\Desktop\SnakeRecog\Models\{user}.jpg"
print(src)
print(path)
urllib.request.urlretrieve(src,path)
HTTP headers 由 name:value 对组成。您需要将这些对列为 addheaders
.
中的元组
opener.addheaders=[('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
urllib.request.urlretrieve(src,path)
行给出了一个异常(给定的参数太多(预期 2)),但我从字典中获取这些值,其中元组具有所有 2 个值。我往南去哪里?
这是代码:
page_soup = soup(text, "lxml")
friends_div=page_soup.find("div",{"class":"j83agx80 btwxx1t3 lhclo0ds i1fnvgqd"})
img=friends_div.findAll("img")
users={}
for image in img:
if image.parent.has_key('href'):
parent=image.parent.parent.parent
users[(parent.select("span")[1].text)]= image['src']
opener = urllib.request.build_opener()
opener.addheaders=[('Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
urllib.request.install_opener(opener)
usersrc=""
filename=""
print(max(len(item) for item in users.items()))
for user ,src in users.items():
path=f"C:\Users\Krist\Desktop\SnakeRecog\Models\{user}.jpg"
print(src)
print(path)
urllib.request.urlretrieve(src,path)
HTTP headers 由 name:value 对组成。您需要将这些对列为 addheaders
.
opener.addheaders=[('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]