在Python3.6.8中,我试图从URL下载一个“文件”,并直接处理它,而不创建本地文件。我尝试了以下代码
import io
import requests
url = "https://raw.githubusercontent.com/enzoftware/random/master/README.md"
response = requests.get(url, stream=True)
with io.BytesIO(response.text) as f:
print(f.readlines())
但我犯了个错误
Traceback (most recent call last):
File "tester.py", line 7, in <module>
with io.BytesIO(response.text) as f:
TypeError: a bytes-like object is required, not 'str'
如何做对
假设您只想逐行阅读它,而不考虑它可能具有的任何文档(html)结构,那么您可以这样做
相关问题 更多 >
编程相关推荐