Is there any simple way to solve this problem? 7 50092
一首诗 wrote:
Is there any simple way to solve this problem?
>>myString = " " myString = myString.replac e(" ", "")
Is this what you want?
pys = 'This string contains two times - end'
pyprint s.replace('&nbs p;', ' '*6)
This string contains two times - end
see http://docs.python.org/lib/string-methods.html
On Oct 30, 6:26 pm, "一首诗" <newpt...@gmail .comwrote:
Is there any simple way to solve this problem?
一首诗 wrote:
Is there any simple way to solve this problem?
Yes, strings have a replace method:
>>s = "abc d ef" s.replace('&n bsp;',' ')
'abc def'
Also various modules that are meant to deal with web and xml and such
have functions to do such operations.
Gary Herron
Oh, I didn't make myself clear.
What I mean is how to convert a piece of html to plain text bu keep as
much format as possible.
Such as convert " " to blank space and convert <brto "\r\n"
Gary Herron wrote:
一首诗 wrote:
Is there any simple way to solve this problem?
Yes, strings have a replace method:
>s = "abc d ef" s.replace('&nb sp;',' ')
'abc def'
Also various modules that are meant to deal with web and xml and such
have functions to do such operations.
Gary Herron
On Oct 30, 6:44 pm, "一首诗" <newpt...@gmail .comwrote:
Oh, I didn't make myself clear.
What I mean is how to convert a piece of html to plain text bu keep as
much format as possible.
Such as convert " " to blank space and convert <brto "\r\n"
Then you can explore the parser, http://docs.python.org/lib/module-HTMLParser.html, like
#!/usr/bin/env python
from HTMLParser import HTMLParser
parsedtext = ''
class Parser(HTMLPars er):
def handle_starttag (self, tag, attrs):
if tag == 'br':
global parsedtext
parsedtext += '\\r\\n'
def handle_data(sel f, data):
global parsedtext
parsedtext += data
def handle_entityre f(self, name):
if name == 'nbsp':
pass
x = Parser()
x.feed('An text<br>')
print parsedtext
Gary Herron wrote:
一首诗 wrote:
Is there any simple way to solve this problem?
Yes, strings have a replace method:
>>s = "abc d ef"
>>s.replace('&n bsp;',' ')
'abc def'
Also various modules that are meant to deal with web and xml and such
have functions to do such operations.
Gary Herron
一首诗 wrote:
Is there any simple way to solve this problem?
corresponds to a non-breaking space, chr(160). if you're only
dealing with this specific XML/HTML entity, you can do
text = text.replace("& nbsp;", " ")
or
text = text.replace("& nbsp;", chr(160))
to handle arbitrary entities and character references, pass the data
through an HTML or XML parser, or use something like: http://effbot.org/zone/re-sub.htm#unescape-html
</F>
一首诗 wrote:
Oh, I didn't make myself clear.
What I mean is how to convert a piece of html to plain text bu keep as
much format as possible.
Such as convert " " to blank space and convert <brto "\r\n"
Gary Herron wrote:
>一首诗 wrote:
>>Is there any simple way to solve this problem?
Yes, strings have a replace method:
>>>>s = "abc d ef" s.replace(' ',' ') >
'abc def'
Also various modules that are meant to deal with web and xml and such have functions to do such operations.
Gary Herron
>>my_translatio ns = '''
" = "
# "<br>=\r\n" "<BR>=\r\n" # Windows
"<br>=\n" "<BR>=\n" # Linux
# Add others to your heart's content
'''
>>import SE # From http://cheeseshop.python.org/pypi/SE/2.2%20beta
>>My_Translat or = SE.SE (my_translation s)
>>print My_Translator ('ABC DEFG <br>XYZ')
ABC DEFG
XYZ
SE can also strip tags and translate all HTM escapes and generally lets
you do ad hoc translations in seconds. You just write them up, make an
SE object from your text an run your data through it. As simple as that.
If you wish further explanations, I'll be happy to explain.
Frederic This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ian justice |
last post by:
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've reduced my form request to a simple text string
entry, instead of my desired optional parameters. As i have been stuck
with a single unfathomable glitch for over a year.
Basically, if i enter queries such as ;
"select * from table" "select * from...
|
by: tertius |
last post by:
Is there a better way to append certain chars in a string with a
backslash that the example below?
chr = "#$%^&_{}" # special chars to look out for
str = "123 45^ & 00 0_" # string to convert
n = "" # init new string
for i in str:
if i in chr: # if special character in str
n+='\\' # append it with a backslash
n+=i
|
by: rbronson1976 |
last post by:
Hi all,
I have a very simple page that Firefox has problems with:
www.absolutejava.com/testing.htm
First of all, this page seems to be perfectly valid XHTML Strict. Both
the W3C validator as well as Page Valet indicate it is valid. The page
is being served with the proper MIME type of "application/xhtml+xml".
Unfortunately, Firefox will not display the page due to a non-breaking
|
by: Robert Mark Bram |
last post by:
Hi All,
I am using the following trim function:
function trim (str) {
return str.replace(/^\s*/g, '').replace(/\s*$/g, '');
}
The problem is that this doesn't trim instances of the " " char -
the non breaking space. Can this be represented in a grep statement at
|
by: Naveen K Kohli |
last post by:
I am try to set the text of the drop down list item as
ListItem li = new ListItem();
li.Text = " "+"MyValue";
myDropDown.Items.Add("li);
The intent is to add a spacing in front of the text. Its not doing what I am
trying to do. The text shows up as "&MyValue"
| |
by: ratnakarp |
last post by:
Hi,
I have a search text box. The user enters the value in the text box and
click on enter button. In code behind on button click i'm writing the
code to get the values from the database and binding it to a repeater
control. This repeater control has multiple text boxes and buttons. Can
you please tell me how can i do paging in this case ?
I'm posting my code below. The problem is that if i click on
"AdjustThisAd" button, it opens...
|
by: K B |
last post by:
Hi again,
I have a gridview, when I get the selecteditem.cells for a column, if
the database column is Null or Empty, and I assign that to my web form
text control, the control reads " " instead of a blank.
Never had this happen before, but I am now using Asp.Net 2.0.
Ideas please?
|
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 "&". 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...
|
by: Just Another Victim of the Ambient Morality |
last post by:
I've done a google search on this but, amazingly, I'm the first guy to
ever need this! Everyone else seems to need the reverse of this. Actually,
I did find some people who complained about this and rolled their own
solution but I refuse to believe that Python doesn't have a built-in
solution to what must be a very common problem.
So, how do I convert HTML to plaintext? Something like this:
<div>This is a string.</div>
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
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...
| |