下面的代码片段在一个新行上打印出每个字符,而不是打印出每一行。我认为这是一个简单的修复,但我不记得这是如何完成的:
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)
