473,769 Members | 6,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Obtaining Webpage Source with Python

How can I obtain the source of a remote webpage (e.g.
http://www.python.org/index.html) using Python?

Something like:

pyPage = open('http://www.python.org/index.html',r). read()

Obviously that won't work but how can I do something to that effect?
Thanks,
Ryan Kaskel

--I posed this before but it seems it is not showing up...
Jul 18 '05 #1
4 3072
ry**@ryankaskel .com (Ryan Kaskel) writes:
Something like:

pyPage = open('http://www.python.org/index.html',r). read()

Obviously that won't work but how can I do something to that effect?


import urllib
pyPage = urllib.urlopen( 'http://www.python.org/index.html',r). read()
Jul 18 '05 #2
Paul Rubin <http://ph****@NOSPAM.i nvalid> writes:
import urllib
pyPage = urllib.urlopen( 'http://www.python.org/index.html',r). read()


oops:

import urllib
pyPage = urllib.urlopen( 'http://www.python.org/index.html').re ad()

i.e. omit the 'r' argument to urlib.urlopen.
Jul 18 '05 #3
pyPage = open('http://www.python.org/index.html',r). read()


using open() for local files and ORLs is called url-fopen and works in
PHP, which is a major security hole, because it even allows one to
include() code files from the web without knowing it, that kind of thing...

python has two functions so you know what you're doing.

If your webpage needs cookies or something, you'll need urllib2

If you wanna parse it afterwards use Htmllib or BeautifulSoup
Jul 18 '05 #4
Take a look at the urllib module:

http://python.org/doc/2.3.3/lib/module-urllib.html

On Wed, Jun 23, 2004 at 10:03:04PM -0700, Ryan Kaskel wrote:
How can I obtain the source of a remote webpage (e.g.
http://www.python.org/index.html) using Python?

Something like:

pyPage = open('http://www.python.org/index.html',r). read()

Obviously that won't work but how can I do something to that effect?
Thanks,
Ryan Kaskel

--I posed this before but it seems it is not showing up...


Jul 18 '05 #5

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

Similar topics

2
2506
by: wonder | last post by:
Hi, How can I pass the url of the current webpage link to a python script in html? thanks sam
3
1765
by: hendedav | last post by:
Hi gang. As with any other post, I am working on a project and have gotten stuck. I am trying to obtain a variable value in the parent webpage from an <iframe>. For instance: Parent Page code ---------------- <html> .... heading tags <body>
15
5846
by: qwweeeit | last post by:
Hi all, Elliot Temple on the 1 June wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no luck. > For example, google has a button <input type=submit value="Google > Search" name=btnG> how would i make a script to press that button? I have a similar target: web automation, which
2
5019
by: brianlum | last post by:
Hi, I have been looking for a good way to convert python code into a control flow graph. I know of Python functions that will convert an expression into an abstract syntax tree (i.e. ast = parser.expr('(x+5)*5') then t = ast.totuple() then t), but I am not sure how to obtain a CFG. I've gone through the compiler and it has code that converts the AST
11
4075
by: John Nagle | last post by:
The Python SSL object offers two methods from obtaining the info from an SSL certificate, "server()" and "issuer()". The actual values in the certificate are a series of name/value pairs in ASN.1 binary format. But what "server()" and "issuer()" return are strings, with the pairs separated by "/". The documentation at "http://docs.python.org/lib/ssl-objects.html" says "Returns a string containing the ASN.1 distinguished name identifying...
6
1453
by: Anton Vredegoor | last post by:
Since a few days I've been experimenting with a construct that enables me to send the sourcecode of the web page I'm reading through a Python script and then into a new tab in Mozilla. The new tab is automatically opened so the process feels very natural, although there's a lot of reading, filtering and writing behind the scene. I want to do three things with this post: A) Explain the process so that people can try it for themselves...
0
1534
by: snsanju | last post by:
Hi, i am writing a program to fetch the portion of the data of a webpage. Here i am using www::mechanize module. I got succeeded to print the part of the web page section but here the problem is, when i see on webpage it shows form, combobox and proper values. But, in view source of that page only few html & javascripts (same view source output also my perl output) are there. form and combobox related html tags(source) is there. In perl...
6
1726
by: Jetus | last post by:
Is there a good place to look to see where I can find some code that will help me to save webpage's links to the local drive, after I have used urllib2 to retrieve the page? Many times I have to view these pages when I do not have access to the internet.
2
12617
by: anumsajeel | last post by:
Hi, Error Message:- error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Target Site:- MySql.Data.MySqlClient.Driver GetConnection() Error Source:- MySql.Data
0
9587
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9993
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
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.