A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Python requests library

1.1k views · started by rosewill ·
#1
[removed]
[removed][/removed]
#2
Riddle had programmed his own HTTP class. That's what I've been using in my Python programs.
#3
Chad wrote:
Riddle had programmed his own HTTP class. That's what I've been using in my Python programs.

His is overly done. Hate to hate on him, but its a nasty class. Heres mine:

import urllib
import urllib2
import cookielib

class HTTPWrapper:
def __init__(self, KeepCookies=True):
if(KeepCookies):
self.cj = cookielib.CookieJar()
self.HTTP = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
else:
self.HTTP = urllib2.build_opener()

def Req(self, URL, data={}):
return self.HTTP.open(URL,urllib.urlencode(data)).read()

def GetBetween(self, s, leader, trailer):
end_of_leader = s.index(leader) + len(leader)
start_of_trailer = s.index(trailer, end_of_leader)
return s[end_of_leader:start_of_trailer]


Beautifully simple!
#4
Matt's is woefully simple :p

If you do use it, you may want to consider building on it a bit ;)
#5
Artificial wrote:
Matt's is woefully simple :p

If you do use it, you may want to consider building on it a bit ;)

Its pretty easy to build upon also :D Simple code is normally the preferred code.