下面的代码片段在一个新行上打印出每个字符,而不是打印出每一行。我认为这是一个简单的修复,但我不记得这是如何完成的:
with requests.Session() as s:
url = 'https://www.zillow.com/<rest of url doesn\'t matter>'
r = s.get(url)
for line in r.text:
print(line)
我知道我可以使用正则表达式在到达行尾时进行打印,但我认为有一种更简洁的方法可以做到这一点。
最佳答案
我认为你必须使用分割线
:
with requests.Session() as s:
url = 'https://www.zillow.com/<rest of url doesn\'t matter>'
r = s.get(url)
for line in str(r.text).splitlines():
print(line)
关于python - 如何从文本 block 而不是字符中提取行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54032096/