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
Problems with CData
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
  2 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
 
Gustavo Ambrozio  
View profile  
 More options Apr 20 2012, 3:19 pm
From: Gustavo Ambrozio <gust...@gustavo.eng.br>
Date: Fri, 20 Apr 2012 12:19:52 -0700 (PDT)
Local: Fri, Apr 20 2012 3:19 pm
Subject: Problems with CData
Hi,

In my html I have a bunch of code like this:

<html><body><script>a="<a href='teste'>";</script></body></html>

If I parse this with BS4 I get what is the correct (in the strict
sense) result:

>>> from bs4 import BeautifulSoup
>>> from bs4 import CData
>>> html = "<html><body><script>a=\"<a href='teste'>\";</script></body></html>"
>>> s = BeautifulSoup(html)
>>> s

<html><body><script>a="&lt;a href='teste'&gt;";</script></body></html>

But even though it's correct it does not work in the browser because
now the browser thinks the variable a is "&lt;a href='teste'&gt;".
Weird but true.

I'd like to get the code wrapped in a cdata, so I did this:

>>> script_text = s.html.body.script.children.next()
>>> cdata = CData(script_text.string)
>>> cdata

u'a="<a href=\'teste\'>";'

>>> script_text.replace_with(cdata)
>>> s

<html><body><script><![CDATA[a="&lt;a href='teste'&gt;";]]></script></
body></html>

Is this the correct behavior? Shouldn't it be?:

<html><body><script><![CDATA[a="<a href='teste'>";]]></script></body></
html>

If not, how can I achieve this? I now that doing:

>>> s.encode(formatter=None)

'<html><body><script><![CDATA[a="<a href=\'teste\'>";]]></script></
body></html>'

Works, but I'd like it to still correct wrong chars inside an <a> tag,
for example and using formatter=None would not correct those, so....

Any help is appreciated.

Cheers,
Gustavo


 
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.
Leonard Richardson  
View profile  
 More options Apr 26 2012, 10:46 am
From: Leonard Richardson <leona...@segfault.org>
Date: Thu, 26 Apr 2012 10:46:38 -0400
Local: Thurs, Apr 26 2012 10:46 am
Subject: Re: Problems with CData
Gustavo,

This is a bug:

https://bugs.launchpad.net/beautifulsoup/+bug/988905

It'll be fixed in the next release.

Leonard

On Fri, Apr 20, 2012 at 3:19 PM, Gustavo Ambrozio


 
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 »