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
why <br> is not regarded as <br /> in some cases
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
  3 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
 
polyrabbit  
View profile  
 More options Oct 26 2012, 2:21 pm
From: polyrabbit <mcx_...@foxmail.com>
Date: Fri, 26 Oct 2012 11:21:47 -0700 (PDT)
Local: Fri, Oct 26 2012 2:21 pm
Subject: why <br> is not regarded as <br /> in some cases

First off, I do have searched a lot on BeautifulSoup and br, but found
nothing related to my problem, so I come to you for help.

In some mal-formatted HTML, <br /> is always written as <br>, which
leads BeautifulSoup to regard it as half of the <br></br> tag, for example:

> print BeautifulSoup('<br>word')

the output is <br>word</br>

But when written along <br> is regarded as a self-close tag:

> print BeautifulSoup('<br>')

yields  <br/>

Why is it resolved in two different ways, and how can I make bs to always
regard <br> as <br/>?
Thank you all in advance..


 
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.
dgspot...@gmail.com  
View profile  
 More options Feb 11, 12:35 pm
From: dgspot...@gmail.com
Date: Mon, 11 Feb 2013 09:35:06 -0800 (PST)
Local: Mon, Feb 11 2013 12:35 pm
Subject: Re: why <br> is not regarded as <br /> in some cases

BeautifulSoup 3 gets this right, BeautifulSoup 4 gets it wrong (<br> is a
void element that should never have any content).

My question is: "Is BeautifulSoup 4 fundamentally broken in this regard, or
is there some option I'm missing that gets it to treat unterminated <br>tags the same way as BeautifulSoup 3 did?" (I would like to use
BeautifulSoup 4, but it's currently making my life difficult in a way that
BeautifulSoup 3 doesn't.)

Here's an example: given two soups (soup3, soup4) constructed from the same
HTML using BeautifulSoup 3 and BeautifulSoup 4, respectively, notice the
"nested" contents of snippet4 as compared to the "flat" contents of snippet3
:

>>> snippet3 = soup3.find(text=re.compile('^Date')).parent.parent
>>> snippet4 = soup4.find(text=re.compile('^Date')).parent.parent
>>> snippet3

<p>
<strong>Date &amp; Time: </strong>02/02/2013 1:02pm<br />
<strong>Invoice Number: </strong><br />
<strong>Auth #: </strong><br />
<strong>Customer Name: </strong>Cards</p>

>>> snippet4

<p>
<strong>Date &amp; Time: </strong>02/02/2013 1:02pm<br>
<strong>Invoice Number: </strong><br>
<strong>Auth #: </strong><br>
<strong>Customer Name: </strong>Cards</br></br></br></p>

>>> snippet3.contents

[u'\n', <strong>Date &amp; Time: </strong>, u'02/02/2013 1:02pm', <br />,
u'\n', <strong>Invoice Number: </strong>, <br />, u'\n', <strong>Auth #:
</strong>, <br />, u'\n', <strong>Customer Name: </strong>, u'Cards']

>>> snippet4.contents

[u'\n', <strong>Date &amp; Time: </strong>, u'02/02/2013 1:02pm', <br>
<strong>Invoice Number: </strong><br>
<strong>Auth #: </strong><br>
<strong>Customer Name: </strong>Cards</br></br></br>]

>>> snippet4.contents[3].contents

[u'\n', <strong>Invoice Number: </strong>, <br>
<strong>Auth #: </strong><br>
<strong>Customer Name: </strong>Cards</br></br>]

 
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.
Aaron DeVore  
View profile  
 More options Feb 11, 11:05 pm
From: Aaron DeVore <aaron.dev...@gmail.com>
Date: Mon, 11 Feb 2013 20:05:01 -0800
Local: Mon, Feb 11 2013 11:05 pm
Subject: Re: why <br> is not regarded as <br /> in some cases

> BeautifulSoup 3 gets this right, BeautifulSoup 4 gets it wrong (<br> is a

void element that should never have any content).

BeautifulSoup 4 with the default parser gets it wrong. BS4 with the
lxml.html backend works as expected. The lxml backend will automatically be
used if lxml is available.

-Aaron DeVore


 
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 »