http - Keeping website open with Python Requests? -


i trying figure out how can keep connection website open. tried using while loop, after url, can see not connected website anymore. how can navigate url, , keep url open entire time while running loop? want loop forever, maybe print data website. here code tried , help!

import requests import time  url = 'https://www.google.com'  s = requests.session()  headers = {'user-agent': 'mozilla/5.0 (windows nt 6.1) applewebkit/537.36 (khtml, gecko) chrome/41.0.2228.0 safari/537.36'}  r = s.get(url, headers=headers)  while true:     print str(r)     time.sleep(10) 

what purpose of question? trying achieve holding open connection?

i doubt can keep open forever, doing should work, extent.

using requests session should ensure http keepalive option set appropriately, , remote server should keep tcp connection open after servicing each http request. if stop sending requests, server timeout connection , close it.

the important point must keep making requests, example:

import requests import time  url = 'https://www.google.com'  s = requests.session() while true:     r = s.get(url)     print(r.text)     time.sleep(10) 

this code should keep connection open , allow multiple requests sent on same tcp connection.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -