473,544 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building browser-like GET request

Hello

I'd like to download pages from a site, but it checks whether
the requests are coming from a live user or a script; If the latter,
the server returns a blank page.

Using a proxy (Paros), I can see what information my script and
FireFox send, and there are a lot of information that Python is
missing:

======== PYTHON ===============
http://www.acme.com/cgi-bin/read?code=123 HTTP/1.1
Accept-Encoding: identity
Host: www.acme.com
Connection: close
User-Agent: Python-urllib/2.4 Paros/3.2.12
======== FIREFOX ===============
http://www.acme.com/cgi-bin/read?code=123 HTTP/1.1
Host: www.acme.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Paros/3.2.12
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5
Accept-Language: fr-fr,en-us;q=0.7,en;q=0 .3
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
=============== ==============

How can Python be told to send the same information?

Thank you.
Apr 21 '07 #1
4 4646
On 21 Apr., 23:28, Gilles Ganault <nos...@nospam. comwrote:
I'd like to download pages from a site, but it checks whether
the requests are coming from a live user or a script; If the latter,
the server returns a blank page.

Using a proxy (Paros), I can see what information my script and
FireFox send, and there are a lot of information that Python is
missing:
Well, I am brand new to Python, so it takes me a lot of guessing, but
since it seems you're using urlib2:

On http://docs.python.org/lib/module-urllib2.html is written that you
may add custom headers to your http requests.
Either by calling "addheader( )" or by passing a dictionary with
headers to the constructor.

I hope that helped and I wasn't telling things you already new.
As a sidenote: For the task you describe I'd rather use an actual
sniffer - such as Wireshark (http://en.wikipedia.org/wiki/Wireshark),
than logs of a Proxy... Not sure wether Wireshark works under Windows,
though.

Good luck!

Apr 21 '07 #2
On 21 Apr 2007 14:47:55 -0700, Björn Keil <ab*****@silber drache.net>
wrote:
>Well, I am brand new to Python, so it takes me a lot of guessing, but
since it seems you're using urlib2:
Thanks. Indeed, it looks like urlib2 is the way to go when going
through a proxy.

For those interested, here's how to download a page through a proxy:

----------------------------
import sys
import urllib
import urllib2
import re

#set up proxy
proxy_info = { 'host' : 'localhost','po rt' : 8080}
proxy_support = urllib2.ProxyHa ndler({"http" :
"http://%(host)s:%(port )d" % proxy_info})
opener = urllib2.build_o pener(proxy_sup port)
urllib2.install _opener(opener)

#call page with specific headers
url = 'http://www.acme.com/cgi-bin/read?code=123'
headers = {
'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows
NT)',
'Accept' :
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5',
'Accept-Language' : 'fr-fr,en-us;q=0.7,en;q=0 .3',
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.7 '
}
#None = GET; set values to use POST
req = urllib2.Request (url, None, headers)

response = urllib2.urlopen (req).read()
log = open('output.ht ml','w')
log.write(respo nse)
log.close()
----------------------------

Thanks.
Apr 21 '07 #3
Björn Keil wrote:
[...]
>
I hope that helped and I wasn't telling things you already new.
As a sidenote: For the task you describe I'd rather use an actual
sniffer - such as Wireshark (http://en.wikipedia.org/wiki/Wireshark),
than logs of a Proxy... Not sure wether Wireshark works under Windows,
though.
On a point of information, Wireshark wokrs very effectively under
Windows. The only thing you shouldn't expect to be able to do is tap
into the loopback network, and that's down to the Windows driver structure.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 22 '07 #4
On Sun, 22 Apr 2007 18:07:57 -0400, Steve Holden <st***@holdenwe b.com>
wrote:
>On a point of information, Wireshark wokrs very effectively under
Windows. The only thing you shouldn't expect to be able to do is tap
into the loopback network, and that's down to the Windows driver structure.
Thanks for the tip. Someone mentionned a lighter alternative to
display what goes on between browser and web server:

PocketSoap's TCPTrace
http://www.pocketsoap.com/tcptrace/
Apr 24 '07 #5

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

Similar topics

6
1457
by: Sridhar R | last post by:
I am looking for a class browser that has these features. 1. Given a symbol (class, method or function) it should giveback the lineno n source code 2. It should be efficient and quick. I looked at the `pyclbr` module, but it's slower. I will be _often_ regenerating the symbols from exactly one python source file. But for an average...
40
2342
by: Tools | last post by:
What's the best browser to test for website accessibility? Is there a free screen reader I can use to test how my site reads best?
7
1691
by: Christopher Benson-Manica | last post by:
Why is building a table with the DOM slower than using an array? IOW, why is var table=document.createDocumentFragment(); for( var i=0; i < 4000; i++ ) { tr=table.insertRow( table.rows.length ); td=tr.appendChild( document.createElement('td') ); td.appendChild( 'foo' ); } someElement.appendChild( table );
16
1807
by: sirsean | last post by:
Hi all. I'm trying to dynamically build menus and objects after my page loads. Data is stored in an XML file and is parsed at runtime into Javascript objects. At the moment, I'm working on creating menu items from these objects. The parsing works fine (using Sarissa), and Firefox builds the menu no problem. IE, however, does not. The...
17
2039
by: Nick | last post by:
I am doing some research into building web applications using Object Oriented techniques. I have found the excellent patterns section on the MSDN site, but other than that I cannot find any good, concrete examples. I know Microsoft are really pushing OO with the .NET Framework and C#, but for web stuff I am finding good examples sparse. Can...
3
241
by: DaveF | last post by:
I need to run a report and then dynamically make a PDF to print. I am looking for examples. Is there any free ways to do this -- David Fetrow Helixpoint LLC. davef@helixpoint.com
3
1481
by: thomson | last post by:
Hi All, While Iam building my solution, the VS 2003 editor get stucked, for a few minutes and after sometimes it gets recovered, and the solution building done, While building i looked into the task manager entry, and it says the program is not responding, after building the solution it says the program is running. It takes good time for me...
2
1108
by: harry | last post by:
Hi all I have a browser based application that I am looking to deploy. I have built an installer but need to have the installer do some permission changes. I am looking for someone to point me in the direction where I can find help on writing scripts for my deployment project. I need to write scripts that will change permissions of files...
1
1214
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
What are the data access choices that I have in building a client-server application with .net 2.0? If the application does not need to support running from browser, do I still need to understand xml web services or .net remoting?
3
1250
Plater
by: Plater | last post by:
Well, I'm not sure where to put this, but I figured people using ajax are more likely to run into these issues. I have been building my own webserver (don't ask, just trust me when I say I have to) from scratch. I have been using the RFCs to correctly generate response headers, particularly the status line: "HTTP/1.0 200 Ok "+crlf "HTTP/1.0...
0
7414
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7359
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
7598
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7757
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
7360
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
5895
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
5288
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
3398
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
651
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.