英文:
Python: What's wrong with this Python Code(requests)?
问题
Here's the translated code part:
import requests
def get_book():
url = "http://search.dangdang.com/"
response = requests.get(url, params={
'key': 'c%D3%EF%D1%D4',
'act': 'input'
})
print(response.text)
if __name__ == "__main__":
get_book()
The issue in your code is that you used parms
instead of params
when passing parameters to the requests.get()
method. I've corrected it to use params
.
英文:
import requests
# import sys
# sys.setdefaultencoding('utf-8')
def get_book():
#http://search.dangdang.com/?key=c%D3%EF%D1%D4&act=input
url="http://search.dangdang.com/"
rest=requests.get(url,parms={
'key':'c%D3%EF%D1%D4',
# "enc":"utf-8",
# "wq":"haixian",
'act':'input'
})
rest = requests.get(url)
print(rest.text)
# rest.json()
# rest.content
#requests.post()
if __name__=="__main__":
get_book()
Process finished with exit code 1
TypeError: request() got an unexpected keyword argument 'parms'
It cannot work.
What's the problem with this code, and how can I fix it?
答案1
得分: 1
使用params
而不是parms
。
import requests
def get_book():
url = "http://search.dangdang.com/"
rest = requests.get(url, params={
'key': 'c%D3%EF%D1%D4',
'act': 'input'
})
rest = requests.get(url)
print(rest.text)
if __name__ == "__main__":
get_book()
英文:
Use params
instead of parms
import requests
# import sys
# sys.setdefaultencoding('utf-8')
def get_book():
#http://search.dangdang.com/?key=c%D3%EF%D1%D4&act=input
url="http://search.dangdang.com/"
rest=requests.get(url,params={
'key':'c%D3%EF%D1%D4',
# "enc":"utf-8",
# "wq":"haixian",
'act':'input'
})
rest = requests.get(url)
print(rest.text)
# rest.json()
# rest.content
#requests.post()
if __name__=="__main__":
get_book()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论