gpt4 book ai didi

python - 在 python 上通过互联网读取文本文件

转载 作者:行者123 更新时间:2023-11-30 22:46:23 26 4
gpt4 key购买 nike

这是互联网上的一个文本文件 (http) http://hughchalmers.com/example.txt 。我如何在 Python 2 中打印它?

人们说这是重复的,我想说它不是重复的,我发现的任何其他脚本都给出了错误 412。

最佳答案

>>> from urllib2 import Request, urlopen
>>> url = 'http://hughchalmers.com/example.txt'
>>> urlopen(Request(url=url, headers={'User-Agent': "hey, it's wim"})).read()
'Exmaple Text'

关于python - 在 python 上通过互联网读取文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40897184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com