peter_CGY 2022-04-05 20:17 采纳率: 75%
浏览 613

module 'requests' has no attribute text是什么意思

问题遇到的现象和发生背景 我正在做一个获取源文件的python程序
问题相关代码,请勿粘贴截图 import requests

if name == 'main':
url = "https://www.sogou.com/"
resquests = requests.get(url=url)
page_text = requests.text
print(page_text)
with open("./sogou.html",'w',encoding ='utf_8') as fp:
fp.write(page_text)
print('爬取结束')

运行结果及报错内容 File "D:\pythonProject\爬虫.py", line 5, in
page_text = requests.text

AttributeError: module 'requests' has no attribute 'text'

我的解答思路和尝试过的方法 csdn上面没有相关的解决方案
我想要达到的结果就简单的解决一下就可以了,如果有大善人再给我讲解一些这段代码是什么意思就太感谢了

with open("./sogou.html",'w',encoding ='utf_8') as fp:
fp.write(page_text)

  • 写回答

3条回答 默认 最新

  • 叶信君.Mr.Yeh 2022-12-07 01:59
    关注

    resquests = requests.get(url=url)
    page_text = requests.text
    print(page_text)

    改成:
    resquests = requests.get(url=url)
    print(resquests.text)
    resquests是请求后获得的响应,打印响应的text属性或者content属性。
    通常写成:
    response = requests.get(url=url, headers=headers)
    print(response.text) 以文本显示
    or
    print(response.content) # 以二进制显示

    评论

报告相同问题?

问题事件

  • 创建了问题 4月5日