Tineing
2020-08-23 23:34
采纳率: 100%
浏览 159

(已解决)python 大佬们我这代码老是出错能帮忙看下吗?

#导入库
import requests
import re
base_url = "https://www.guokr.com/ask/highlight/"

验证身份 请求姿态

herdenrs = {"User-Agent":" Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"}

发送请求 获得响应数据 每次写到这里都报错又找不到原因

response = requests.get(url=base_url,herdenrs=herdenrs)
print(response)

'''
下面是报错

Traceback (most recent call last):
File "C:/python/小说爬取.py", line 8, in
response = requests.get(url=base_url,herdenrs=herdenrs)
File "C:\python\venv\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\python\venv\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
TypeError: request() got an unexpected keyword argument 'herdenrs'
'''

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • blownewbee 2020-08-24 08:49
    已采纳

    herdenrs

    headers ,拼写错误。

    点赞 打赏 评论
  • 浪天林 2020-08-24 08:49

    response = requests.get(url=base_url,herdenrs=herdenrs)这行的第一个headers拼写错了
    herdenrs = {"User-Agent":" Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"}好像也有点问题
    headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'} 这是我在浏览器上复制的

    点赞 打赏 评论
  • 代码的灵魂是bug! 2020-08-24 09:39

    response = requests.get(url=base_url,herdenrs=herdenrs)
    ->
    response = requests.get(url=base_url,headers=herdenrs)

    点赞 打赏 评论
  • 火创始人 2021-03-05 14:38

    #导入库

    import requests

    import re

    base_url = "https://www.guokr.com/ask/highlight/"

    验证身份 请求姿态

    herdenrs = {"User-Agent":" Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"}

    发送请求 获得响应数据 每次写到这里都报错又找不到原因

    response = requests.get(url=base_url,herdenrs=herdenrs)
    print(response)

    '''
    下面是报错

    Traceback (most recent call last):
    File "C:/python/小说爬取.py", line 8, in
    response = requests.get(url=base_url,herdenrs=herdenrs)
    File "C:\python\venv\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
    File "C:\python\venv\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
    TypeError: request() got an unexpected keyword argument 'herdenrs'
    '''

    点赞 打赏 评论
  • 火创始人 2021-03-05 14:58
    #导入库
    
    import requests
    
    import re
    
    base_url = "https://www.guokr.com/ask/highlight/"
    
    验证身份 请求姿态
    
    herdenrs = {"User-Agent":" Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"}
    
    发送请求 获得响应数据 每次写到这里都报错又找不到原因
    
    response = requests.get(url=base_url,herdenrs=herdenrs)
    print(response)
    点赞 打赏 评论

相关推荐 更多相似问题