Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
UnicodeWarning
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pat  
View profile  
 More options Apr 18 2008, 6:48 pm
From: Pat <patrick.g.c...@gmail.com>
Date: Fri, 18 Apr 2008 15:48:56 -0700 (PDT)
Local: Fri, Apr 18 2008 6:48 pm
Subject: UnicodeWarning
Hey everyone, i'm new at BS so picked up the documentation and
starting trying the examples for parsing XML.

I get all of 3 lines into the script when I get this warning:
"
BeautifulSoup.py:1611: UnicodeWarning: Unicode equal comparison failed
to convert both arguments to Unicode - interpreting them as being
unequal
  elif data[:3] == '\xef\xbb\xbf':
BeautifulSoup.py:1614: UnicodeWarning: Unicode equal comparison failed
to convert both arguments to Unicode - interpreting them as being
unequal
  elif data[:4] == '\x00\x00\xfe\xff':
BeautifulSoup.py:1617: UnicodeWarning: Unicode equal comparison failed
to convert both arguments to Unicode - interpreting them as being
unequal
  elif data[:4] == '\xff\xfe\x00\x00':
"

To do that I did the follow, can anyone help me discern what the heck
I did wrong?

xml = "http://gd2.mlb.com/components/game/mlb/year_2008/month_04/
day_08/gid_2008_04_08_atlmlb_colmlb_1/inning/inning_1.xml"

import urllib
xmlpage = urllib.urlopen(xml)
from BeautifulSoup import BeautifulStoneSoup
soup = BeautifulStoneSoup(xmlpage)

That's where the error comes in....

On a lark i tried using urllib2...that didn't trigger the error....Why
does urllib cause all the drama in BS while urllib2 doesn't?
thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kent Johnson  
View profile  
 More options Apr 19 2008, 12:00 pm
From: Kent Johnson <ken...@tds.net>
Date: Sat, 19 Apr 2008 12:00:29 -0400
Local: Sat, Apr 19 2008 12:00 pm
Subject: Re: UnicodeWarning

Pat wrote:
> import urllib
> xmlpage = urllib.urlopen(xml)

Try
   xmlpage = urllib.urlopen(xml).read()

Kent


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
PATRICK CAIN  
View profile  
 More options Apr 19 2008, 12:54 pm
From: "PATRICK CAIN" <patrick.g.c...@gmail.com>
Date: Sat, 19 Apr 2008 09:54:30 -0700
Local: Sat, Apr 19 2008 12:54 pm
Subject: Re: UnicodeWarning

thanks kent.

i've never used a parser before (i'm totally new at all of this) and i'm
trying to scrape xml pages that look like this....

<pitch des="In play, no out" id="4" type="X" x="120.17" y="147.65"
sv_id="080408_183820" start_speed="96.8" end_speed="88.1" sz_top="3.221"
sz_bot="1.58" pfx_x="-4.073" pfx_z="5.789" px="-0.537" pz="2.618"
x0="-1.786" y0="50.0" z0="6.269" vx0="4.94" vy0="-141.752" vz0="-6.468"
ax="-8.164" ay="36.947" az="-20.499" break_y="23.7" break_angle="17.4"
break_length="4.7" pitch_type="FA" type_confidence="1.2611603255950259"/>

my approach to date has been doing a lot of .split() and the knowing each
variable's index...everyone I tell looks at me like im crazy and says to
learn a parser...

can you push me in a direction w/ BS that might help me?

thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kent Johnson  
View profile  
 More options Apr 19 2008, 2:50 pm
From: Kent Johnson <ken...@tds.net>
Date: Sat, 19 Apr 2008 14:50:13 -0400
Local: Sat, Apr 19 2008 2:50 pm
Subject: Re: UnicodeWarning

In [1]: from BeautifulSoup import BeautifulStoneSoup
In [2]: data = '''<pitch des="In play, no out" id="4" type="X"
x="120.17" y="147.65" sv_id="080408_183820" start_speed="96.8"
end_speed="88.1" sz_top="3.221" sz_bot="1.58" pfx_x="-4.073"
pfx_z="5.789" px="-0.537" pz="2.618" x0="-1.786" y0="50.0" z0="6.269"
vx0="4.94" vy0="-141.752" vz0="-6.468" ax="-8.164" ay="36.947"
az="-20.499" break_y="23.7" break_angle="17.4" break_length="4.7"
pitch_type="FA" type_confidence="1.2611603255950259"/>'''
In [3]: soup=BeautifulStoneSoup(data)
In [5]: soup.pitch
Out[5]: <pitch des="In play, no out" id="4" type="X" x="120.17"
y="147.65" sv_id="080408_183820" start_speed="96.8" end_speed="88.1"
sz_top="3.221" sz_bot="1.58" pfx_x="-4.073" pfx_z="5.789" px="-0.537"
pz="2.618" x0="-1.786" y0="50.0" z0="6.269" vx0="4.94" vy0="-141.752"
vz0="-6.468" ax="-8.164" ay="36.947" az="-20.499" break_y="23.7"
break_angle="17.4" break_length="4.7" pitch_type="FA"
type_confidence="1.2611603255950259"></pitch>
In [6]: soup.pitch['des']
Out[6]: u'In play, no out'
In [7]: soup.pitch['x']
Out[7]: u'120.17'

etc.

Kent


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »