473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

simple Question about using BeautifulSoup


Okay, I have used BeautifulSoup a lot lately, but I am wondering, how do you
open a local html file?

Usually I do something like this for a url

soup = BeautifulSoup(urllib.urlopen('http://www.website.com')

but the file extension doesn't work. So how do I open one?
--
View this message in context: http://www.nabble.com/simple-Questio...p19069980.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Aug 20 '08 #1
2 5583
On 2008-08-20, Alexnb <al********@gmail.comwroted:
Okay, I have used BeautifulSoup a lot lately, but I am wondering, how do you
open a local html file?

Usually I do something like this for a url

soup = BeautifulSoup(urllib.urlopen('http://www.website.com')

but the file extension doesn't work. So how do I open one?
Have you tried the local file URL, like "file:///home/user/file.html"?

GS
--
Grzegorz Staniak <gstaniak _at_ wp [dot] pl>
Aug 20 '08 #2
Alexnb wrote:
>
Okay, I have used BeautifulSoup a lot lately, but I am wondering, how do
you open a local html file?

Usually I do something like this for a url

soup = BeautifulSoup(urllib.urlopen('http://www.website.com')

but the file extension doesn't work. So how do I open one?
The docs for urllib.urlopen clearly state that it returns a file-like
object. Which BS seems to grok.

So... how about passing another file-like object, like... *drumroll* - a
file?

soup = BeautifulSoup(open("myfile.html"))

Apart from the documented possibility to pass the html as string, which
means
soup = BeautifulSoup(open("myfile.html").read())

will work as well.

Diez
Aug 20 '08 #3

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

Similar topics

7
by: Dan Stromberg | last post by:
I'm working on writing a program that will synchronize one database with another. For the source database, we can just use the python sybase API; that's nice and normal. For the target...
1
by: Dan Stromberg | last post by:
Has anyone tried to construct an HTML janitor script using BeautifulSoup? My situation: I'm trying to convert a series of web pages from .html to palmdoc format, using plucker, which is...
4
by: joe_public34 | last post by:
Hello all, I'm trying to write a script to log into Yahoo! (mail, groups, etc), but when I pass the full URL with all form elements via Python, I get a resutling 400 - Bad Request page. When I...
4
by: William Xu | last post by:
Hi, all, This piece of code used to work well. i guess the error occurs after some upgrade. >>> import urllib >>> from BeautifulSoup import BeautifulSoup >>> url = 'http://www.google.com'...
5
by: John Nagle | last post by:
This, which is from a real web site, went into BeautifulSoup: <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer fantastic rates for selected weeks or days!!&blinkt=Click...
3
by: John Nagle | last post by:
Are weak refs slower than strong refs? I've been considering making the "parent" links in BeautifulSoup into weak refs, so the trees will release immediately when they're no longer needed. In...
2
by: Alexnb | last post by:
Okay, I am not sure if there is a better way of doing this than findAll() but that is how I am doing it right now. I am making an app that screen scapes dictionary.com for definitions. However, I...
1
by: Alexnb | last post by:
Okay, what I want to do with this code is to got to thesaurus.reference.com and then search for a word and get the syns for it. Now, I can get the syns, but they are still in html form and some are...
1
by: Jean-Paul Calderone | last post by:
On Wed, 20 Aug 2008 07:33:32 -0700 (PDT), Alexnb <alexnbryan@gmail.comwrote: urllib.urlopen gives you a file-like object for a resource at an url. file gives you a file-like object for a file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.