473,545 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urllib2/Pycurl/HTTP Speeds?

For the Program I Am Making I Make Multiple HTTP Request to My Server.
I found that using urllib2 it was pretty slow, when I activated the
program and tested it it would hang from 2secs-5secs since I am doing
it multiple times I wanted to speed it up by using pycurl. But I got
the samething. Here is my code:

import urllib
import os.path
import cookielib
import pycurl
import StringIO

class GoToPage:
#HTTPHeaders = {'User-agent' : self.browser, 'Accept-Language:
en-us' : 'en-us', 'Accept-Encoding' : 'deflate'}
FireFox_15 = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6"
IE7_B2 = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;
..NET CLR 1.1.4322)"
Opera_85 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en)
Opera 8.51"
IE6 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
Mozilla_17 = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;
rv:1.7b) Gecko/20040404"
def __init__(self, myName):
self.browser = self.FireFox_15
self.lastPage = ""
self.cookies = ""
self.name = myName
self.wrapper = pycurl.Curl()

#self.wrapper.s etopt(pycurl.AU TOREFERER, 0)
self.wrapper.se topt(pycurl.COO KIEFILE, self.name)
#self.cookieJar = cookielib.LWPCo okieJar()
#if self.cookieJar != None:
# if os.path.isfile( self.name):
# self.cookieJar. load(self.name)
#self.opener =
urllib2.build_o pener(urllib2.H TTPCookieProces sor(self.cookie Jar))
#urllib2.instal l_opener(self.o pener)
return #end Function
def buildHeaders(se lf, browser, referer=""):
if referer != "":
buildHeaders = ['User-agent: ' + self.browser,
'Accept-Language: en-us', 'Accept-Encoding:
gzip,compress;q =0.9,deflate;q= 0', 'Referer:' + referer]
else:
buildHeaders = ['User-agent: ' + self.browser,
'Accept-Language: en-us', 'Accept-Encoding:
gzip,compress;q =0.9,deflate;q= 0']
return buildHeaders
def saveCookies(sel f, cookies):
fileHandle = open (self.name, 'w')
fileHandle.writ e (cookies)
fileHandle.clos e()
def GetPage(self, URL, referer=""):
theHeaders = self.buildHeade rs(self.browser , referer)
returnVal = StringIO.String IO()
self.wrapper.se topt(pycurl.URL , URL)
self.wrapper.se topt(pycurl.HTT PHEADER, theHeaders)
self.wrapper.se topt(pycurl.WRI TEFUNCTION, returnVal.write )
self.wrapper.pe rform()
self.wrapper.cl ose()
#self.saveCooki es(self.wrapper .getinfo(pycurl .COOKIELIST))
#self.cookieJar .save(self.name )
return returnVal.getva lue()

def PostPage(self, URL, data, referer=""):
timer = wx.StopWatch()
theHeaders = self.buildHeade rs(self.browser , referer)
print timer.Time()
timer.Start(0)
returnVal = StringIO.String IO()
self.wrapper.se topt(pycurl.URL , URL)
self.wrapper.se topt(pycurl.POS TFIELDS, data)
self.wrapper.se topt(pycurl.HTT PHEADER, theHeaders)
self.wrapper.se topt(pycurl.WRI TEFUNCTION, returnVal.write )
print str(timer.Time( )) + ' before perform'
timer.Start(0)
self.wrapper.pe rform()
print str(timer.Time( )) + ' after perform'
self.wrapper.cl ose()
#self.saveCooki es(self.wrapper .getinfo(pycurl .COOKIELIST))
#self.cookieJar .save(self.name )
return returnVal.getva lue()

The Urlib2 source is lost, and there are timer functions in there. I
call it like this

import GoToPage
newHTTP = GoToPage.GoToPa ge("name")

Aug 8 '06 #1
0 2546

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6348
by: Mark Ferguson | last post by:
I've been trying to get a simple pycurl script working with an authenticating proxy, here is the code (with changes to protect the guilty!): from pycurl import * import StringIO b = StringIO.StringIO() c = Curl()
0
1803
by: Jesse Noller | last post by:
The problem: I am writing a file uploading utility in python that uses the walk() function to parse a directory, finding any file under that directory, and upload it to a remote server using the pyCURL curl interface. The files are invariably binary files, and the upload method is via an HTTP PUT to the system. I also need to perform the...
2
6075
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line #80 and line # 38 are the first line offenders. --> --> -->
1
2758
by: tomazi75-nospam(at)gmail.com | last post by:
Hello all, I've a problem using urllib2 with a proxy which need authentication. I've tested the 'simple way' : -- code -- import urllib # example values for the post
1
2816
by: dmbkiwi | last post by:
I've been using urllib2 to try and automate logging into the google adsense page. I want to download the csv report files, so that I can do some analysis of them. However, I don't really know how web forms work, and the examples on the python.org/doc site aren't really helpful. I've found working scripted login code using javascript, but...
4
7219
by: Ju Hui | last post by:
I wanna use urllib2 to get a page with a socks 5 proxy,who can give me a sample code ? example, the proxy server is :123.123.123.123 and the port is :1080 and the username/password is : user/pass I want to open http://www.google.com how to write this kind of script?
1
5956
by: Ju Hui | last post by:
I download it from http://pycurl.sourceforge.net/ and then extract it to D:\usr\pycurl-7.15.2 then D:\usr\pycurl-7.15.2>setup.py install --curl-dir=d:\usr\pycurl-7.15.2 Using curl directory: d:\usr\pycurl-7.15.2 Traceback (most recent call last): File "D:\usr\pycurl-7.15.2\setup.py", line 197, in ? assert os.path.isfile(o), o...
4
10020
by: Ju Hui | last post by:
import pycurl c = pycurl.Curl() c.setopt( pycurl.URL, 'http://www.test.com/test.html' ) import StringIO b = StringIO.StringIO() c.setopt( c.WRITEFUNCTION, b.write ) c.setopt( c.FOLLOWLOCATION, 1 ) c.setopt( c.MAXREDIRS, 5 ) c.setopt(c.PROXY,'www.test.com:1080') #c.setopt(c.PROXYTYPE,'SOCKS5')
1
1739
by: pabloski | last post by:
Hi to all, I have a problem with a snippet of code that creates a Curl object the code is c = pycurl.Curl() c.key = keyCurrent c.proxy = proxyCurrent c.url = "http://www.google." + lg + "/search?hl=" + lg + "&q=" + c.key +
0
7408
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7433
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5340
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1891
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.