473,702 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BeautifulSoup error

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'
port = urllib.urlopen( url).read()
soup = BeautifulSoup()
soup.feed(port) Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/sgmllib.py", line 94, in feed
self.rawdata = self.rawdata + data
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xb8 in position 565: ordinal not in range(128)


Any ideas to solve this?

version info:

Python 2.3.5 (#2, Mar 7 2006, 12:43:17)
[GCC 4.0.3 20060212 (prerelease) (Debian 4.0.2-9)] on linux2

python-beautifulsoup: 3.0.1-1

--
William

"I'd love to go out with you, but I have to floss my cat."
Jun 16 '06 #1
4 2729
William Xu wrote:
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'
port = urllib.urlopen( url).read()
soup = BeautifulSoup()
soup.feed(port) Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/sgmllib.py", line 94, in feed
self.rawdata = self.rawdata + data
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xb8 in position 565: ordinal not in range(128)

Any ideas to solve this?


According to the documentation
<http://www.crummy.com/software/BeautifulSoup/documentation.h tml>
chapter "Beautiful Soup Gives You Unicode, Dammit" Beautiful Soup fully
supports unicode so it's probably a bug.
version info:

Python 2.3.5 (#2, Mar 7 2006, 12:43:17)
[GCC 4.0.3 20060212 (prerelease) (Debian 4.0.2-9)] on linux2

python-beautifulsoup: 3.0.1-1


Upgrading python-beautifulsoup is a good idea, since there were two bug
fix releases after 3.0.1

Jun 16 '06 #2
"Serge Orlov" <Se*********@gm ail.com> writes:

[...]
Upgrading python-beautifulsoup is a good idea, since there were two bug
fix releases after 3.0.1


I just downloaded latest version 3.0.3 from its homepage, seems it still
has the same problem.

--
William

PL/I -- "the fatal disease" -- belongs more to the problem set than to the
solution set.
-- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5
Jun 16 '06 #3
William Xu wrote:
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'
port = urllib.urlopen( url).read()
soup = BeautifulSoup()
soup.feed(port)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/sgmllib.py", line 94, in feed


Look at the traceback: you're not calling BeautifulSoup module! In
fact, there is no feed method in the current BeautifulSoup
documentation. Maybe it used to work well, but now it's definitely
going to fail. As I understand documentation you need to write

soup = BeautifulSoup(p ort)

Jun 16 '06 #4
"Serge Orlov" <Se*********@gm ail.com> writes:

[...]
Look at the traceback: you're not calling BeautifulSoup module! In
fact, there is no feed method in the current BeautifulSoup
documentation. Maybe it used to work well, but now it's definitely
going to fail. As I understand documentation you need to write

soup = BeautifulSoup(p ort)


Ah, yes ! Things change ! :-)

BeautifulSoup feed() method used to exist before 3.0.0, and was left
over to SGMLParser later. As explained in the changlog,

http://www.crummy.com/software/Beaut...CHANGELOG.html

Release 3.0.0 (2006/05/28), "Who would not give all else for two p"

Beautiful Soup no longer implements a feed method. You need to pass a
string or a filehandle into the soup constructor, not with feed after
the soup has been created. There is still a feed method, but it's the
feed method implemented by SGMLParser and calling it will bypass
Beautiful Soup and cause problems.

Thanks for all the help !

--
William

Thrashing is just virtual crashing.
Jun 16 '06 #5

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

Similar topics

4
3119
by: Steve Young | last post by:
I tried using BeautifulSoup to make changes to the url links on html pages, but when the page was displayed, it was garbled up and didn't look right (even when I didn't actually change anything on the page yet). I ran these steps in python to see what was up: >>from BeautifulSoup import BeautifulSoup >>from urllib2 import build_opener, Request >> >>req = Request('http://www.python.org/')
1
3897
by: ye juan | last post by:
Hi, Anyone tries to use BeautifulSoup ( http://www.crummy.com/software/BeautifulSoup/ ) in Jython? I can not run that ,the error that Jython gives me is: unpack sequence too long. Sincerely, Erica
7
8601
by: Gonzillaaa | last post by:
I'm trying to get the data on the "Central London Property Price Guide" box at the left hand side of this page http://www.findaproperty.com/regi0018.html I have managed to get the data :) but when I start looking for tables I only get tables of depth 1 how do I go about accessing inner tables? same happens for links... this is what I've go so far
7
4618
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get BeautifulSoup to clean those up? There are various parsing options related to "&" handling, but none of them seem to do quite the right thing. If I write the BeautifulSoup parse tree back out with "prettify", the loose "&" is still in there. So...
5
2655
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 here And this came out, via prettify: <addresssnippet siteurl="http%3A//apartmentsapart.com" url="http%3A//www.apartmentsapart.com/Europe/Spain/Madrid/FAQ"> <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer
9
1761
by: Mizipzor | last post by:
Is there a way to "subscribe" to individual topics? im currently getting bombarded with daily digests and i wish to only receive a mail when there is activity in a topic that interests me. Can this be done? Thanks in advance.
11
3172
by: John Nagle | last post by:
The syntax that browsers understand as HTML comments is much less restrictive than what BeautifulSoup understands. I keep running into sites with formally incorrect HTML comments which are parsed happily by browsers. Here's yet another example, this one from "http://www.webdirectory.com". The page starts like this: <!Hello there! Welcome to The Environment Directory!> <!Not too much exciting HTML code here but it does the job! >...
5
3770
by: Larry Bates | last post by:
Info: Python version: ActivePython 2.5.1.1 Platform: Windows I wanted to install BeautifulSoup today for a small project and decided to use easy_install. I can install other packages just fine. Unfortunately I get the following error from BeautifulSoup installation attempt: C:\Python25\Lib\SITE-P~1>easy_install BeautifulSoup
3
2167
by: bsagert | last post by:
I downloaded BeautifulSoup.py from http://www.crummy.com/software/BeautifulSoup/ and being a n00bie, I just placed it in my Windows c:\python25\lib\ file. When I type "import beautifulsoup" from the interactive prompt it works like a charm. This seemed too easy in retrospect. Then I downloaded the PIL (Python Imaging Library) module from http://www.pythonware.com/products/pil/. Instead of a simple file that BeautifulSoup sent me, PIL is...
0
8652
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
9089
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
8983
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
8940
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7831
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
6575
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
5907
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3107
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

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.