473,722 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BeautifulSoup vs. Microsoft

Here's a construct with which BeautifulSoup has problems. It's
from "http://support.microso ft.com/contactussuppor t/?ws=support".

This is the original:
<a href="http://www.microsoft.c om/usability/enroll.mspx"
id="L_75998"
title="<!--http://www.microsoft.c om/usability/information.msp x->"
onclick="return MS_HandleClick( this,'C_32179', true);">
Help us improve our products
</a>
And this is what comes back after parsing with BeautifulSoup
and using "prettify":
<a href="http://www.microsoft.c om/usability/enroll.mspx"
id="L_75998"
title="&lt;!--http://www.microsoft.c om/usability/information.msp x-&gt;">
<br clear="all" style="line-height: 1px; overflow: hidden" />
<table id="msviFooter " width="100%" cellpadding="0"
cellspacing="0" >
<tr valign="bottom" >

<td id="msviFooter2 "
style="filter:p rogid:DXImageTr ansform.Microso ft.Gradient(sta rtColorStr='#FF FFFF',
endColorStr='#3 F8CDA', gradientType='1 ')">
<div id="msviLocalFo oter">
<nobr>
</nobr>
</div>
</td>
</tr>
</table>
</a>

All that other stuff is in the neighborhood, but not in that <atag.

Strictly speaking, it's Microsoft's fault.

title="<!--http://www.microsoft.c om/usability/information.msp x->"

is supposed to be an HTML comment. But it's improperly terminated.
It should end with "-->". So all that following stuff is from what
follows the next "-->" which terminates a comment.

It's so Microsoft.

Unfortunately, even Firefox accepts bad comments like that.

Anyway, a BeautifulSoup question. "findall(text=T rue)" collects comments,
processing instructions, etc. as well as real text. What's the right way
to collect ordinary text only?

John Nagle

Mar 29 '07 #1
6 1888
John Nagle <na***@animats. comwrote:
Strictly speaking, it's Microsoft's fault.

title="<!--http://www.microsoft.c om/usability/information.msp x->"

is supposed to be an HTML comment. But it's improperly terminated.
It should end with "-->". So all that following stuff is from what
follows the next "-->" which terminates a comment.
It is an attribute value, and unescaped angle brackets are valid in
attributes. It looks to me like a bug in BeautifulSoup.
Mar 29 '07 #2
On Mar 29, 4:08 pm, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
John Nagle <n...@animats.c omwrote:
title="<!--http://www.microsoft.c om/usability/information.msp x->"
is supposed to be an HTML comment. But it's improperly terminated.

It is an attribute value, and unescaped angle brackets are valid in
attributes. It looks to me like a bug in BeautifulSoup.
FWIW, see http://tinyurl.com/yjtzjz

new fan of BeautifulSoup here as it helped me parse "BAD" XML
(although my client would disagree with that description)

Mar 29 '07 #3
On Mar 29, 6:11 pm, "Justin Ezequiel" <justin.mailing li...@gmail.com >
wrote:
>
FWIW, seehttp://tinyurl.com/yjtzjz
hmm. not quite right.

http://tinyurl.com/ynv4ct

or

http://www.crummy.com/software/Beaut...20the%20Parser

Mar 29 '07 #4
"Justin Ezequiel" <ju************ *****@gmail.com wrote:
On Mar 29, 4:08 pm, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
>John Nagle <n...@animats.c omwrote:
title="<!--http://www.microsoft.c om/usability/information.msp x->"
is supposed to be an HTML comment. But it's improperly terminated.

It is an attribute value, and unescaped angle brackets are valid in
attributes. It looks to me like a bug in BeautifulSoup.

FWIW, see http://tinyurl.com/yjtzjz

new fan of BeautifulSoup here as it helped me parse "BAD" XML
(although my client would disagree with that description)
I'm right behind BeautifulSoup's ability to parse bad HTML, but I still
think it should give priority to being able to parse valid HTML withough
messing it up.
Mar 29 '07 #5
On Mar 29, 1:50 am, John Nagle <n...@animats.c omwrote:
Here's a construct with which BeautifulSoup has problems. It's
from "http://support.microso ft.com/contactussuppor t/?ws=support".

This is the original:

<a href="http://www.microsoft.c om/usability/enroll.mspx"
id="L_75998"
title="<!--http://www.microsoft.c om/usability/information.msp x->"
onclick="return MS_HandleClick( this,'C_32179', true);">
Help us improve our products
</a>
<snip>
>
Strictly speaking, it's Microsoft's fault.

title="<!--http://www.microsoft.c om/usability/information.msp x->"

is supposed to be an HTML comment. But it's improperly terminated.
It should end with "-->". So all that following stuff is from what
follows the next "-->" which terminates a comment.
No, that comment is inside a quoted string, so it should be ok.

If you are just trying to extract <a href=...tags, this pyparsing
scraper gets them, including this problematic one:
import urllib
from pyparsing import makeHTMLTags

pg = urllib.urlopen( "http://support.microso ft.com/contactussuppor t/?
ws=support")
htmlSrc = pg.read()
pg.close()

# only take first tag returned from makeHTMLTags, not interested in
# closing </atags
anchorTag = makeHTMLTags("A ")[0]

for a in anchorTag.searc hString(htmlSrc ):
if "title" in a:
print "Title:", a.title
print "HREF:", a.href
# or use this statement to dump the complete tag contents
# print a.dump()
print

Prints:
Title: <!--http://www.microsoft.c om/usability/information.msp x->
HREF: http://www.microsoft.com/usability/enroll.mspx

Title: Print this page
HREF: /gp/noscript/

Title: Print this page
HREF: /gp/noscript/

Title: E-mail this page
HREF: mailto:?subject =Help%20and%20S upport&amp;body =http%3a%2f
%2fsupport.micr osoft.com%2fdef ault.aspx%2fcon tactussupport%2 f%3fws
%3dsupport

Title: E-mail this page
HREF: mailto:?subject =Help%20and%20S upport&amp;body =http%3a%2f
%2fsupport.micr osoft.com%2fdef ault.aspx%2fcon tactussupport%2 f%3fws
%3dsupport

Title: Microsoft Worldwide
HREF: /common/international.a spx?rdPath=0

Title: Microsoft Worldwide
HREF: /common/international.a spx?rdPath=0

Title: Save to My Support Favorites
HREF: /gp/noscript/

Title: Save to My Support Favorites
HREF: /gp/noscript/

Title: Go to My Support Favorites
HREF: /gp/noscript/

Title: Go to My Support Favorites
HREF: /gp/noscript/

Title: Send Feedback
HREF: /gp/noscript/

Title: Send Feedback
HREF: /gp/noscript/

-- Paul

Mar 29 '07 #6
Duncan Booth wrote:
John Nagle <na***@animats. comwrote:

>>Strictly speaking, it's Microsoft's fault.

title="<!--http://www.microsoft.c om/usability/information.msp x->"

is supposed to be an HTML comment. But it's improperly terminated.
It should end with "-->". So all that following stuff is from what
follows the next "-->" which terminates a comment.


It is an attribute value, and unescaped angle brackets are valid in
attributes. It looks to me like a bug in BeautifulSoup.
I think you're right. The HTML 4 spec,

http://www.w3.org/TR/html4/intro/sgmltut.html

says "Note that comments are markup". So recognizing comment syntax
inside an attribute is, in fact, an error in BeautifulSoup.

The source HTML on the Microsoft page is thus syntactically correct,
although meaningless. That's the only place on that page with a
comment-type form in an attribute.

John Nagle
Mar 29 '07 #7

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

Similar topics

4
3122
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/')
7
8603
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
4
2731
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' >>> port = urllib.urlopen(url).read() >>> soup = BeautifulSoup()
5
2657
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
1765
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
3175
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
3771
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
2171
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...
2
2616
by: academicedgar | last post by:
Hi I would appreciate some help. I am trying to learn Python and want to use BeautifulSoup to pull some data from tables. I was really psyched earlier tonight when I discovered that I could do this from BeautifulSoup import BeautifulSoup bst=file(r"c:\bstest.htm").read() soup=BeautifulSoup(bst) rows=soup.findAll('tr')
0
8863
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
9384
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
9238
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
9157
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
9088
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
5995
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
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3207
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
3
2147
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.