Hello,
***************
import urllib2
import re
import string
import sys
url = "http://www.macgyver.co m/"
request = urllib2.Request (url)
opener = urllib2.build_o pener()
html = opener.open(req uest).read()
match = re.compile("<PR E>(.+)</PRE>", re.DOTALL)
out = match.findall(h tml)
print out
**************
I would like to print out string with formatting, but as I read, the
string is made into a raw string when using re.
How could I disable or bypass this?
I googled for an hour and couldn't find a solution.
Thank you in advance. 5 1514 ku*******@kurat kull.com wrote:
Hello,
***************
import urllib2
import re
import string
import sys
url = "http://www.macgyver.co m/"
request = urllib2.Request (url)
opener = urllib2.build_o pener()
html = opener.open(req uest).read()
match = re.compile("<PR E>(.+)</PRE>", re.DOTALL)
out = match.findall(h tml)
print out
**************
I would like to print out string with formatting, but as I read, the
string is made into a raw string when using re.
How could I disable or bypass this?
You have a misconception here. A raw-string in python is *only* different as
literal - that is, you can write
r"fooo\bar"
where you'd have to write
"fooo\\bar"
with "normal" string-literals. However, the result of both is a byte-string
object that is exactly equal. So whatever out contains, it has nothing to
do with raw-string or not.
But what you probably mean is that putting out a list using print will use
the repr()-call on the contained objects. So instead of doing
print out
do
print "\n".join(o ut)
or such.
Diez
On May 19, 4:54*am, kuratk...@kurat kull.com wrote:
Hello,
***************
import urllib2
import re
import string
import sys
url = "http://www.macgyver.co m/"
request = urllib2.Request (url)
opener = urllib2.build_o pener()
html = opener.open(req uest).read()
match = re.compile("<PR E>(.+)</PRE>", re.DOTALL)
out = match.findall(h tml)
print out
**************
I would like to print out string with formatting, but as I read, the
string is made into a raw string when using re.
How could I disable or bypass this?
I googled for an hour and couldn't find a solution.
Thank you in advance.
Change your print statement to:
print out[0]
-- Paul
On May 19, 4:54*am, kuratk...@kurat kull.com wrote:
Hello,
<snip code example scraping a QOTD from www.mcgyver.com >
>
print out
**************
Since you have no control over spacing and line breaks in the input,
you can reformat using the textwrap module. First replace all "\n"s
with " ", then use re.sub to replace multiple spaces with a single
space, then call textwrap.fill to reformat the line into lines up to
'n' characters long (I chose 50 in the sample below, but you can
choose any line length you like).
out = match.findall(h tml)
out = out[0].replace("\n"," ")
out = re.sub("\s+"," ",out)
print textwrap.fill(o ut,50)
-- Paul
On May 19, 8:09*am, Paul McGuire <pt...@austin.r r.comwrote:
On May 19, 4:54*am, kuratk...@kurat kull.com wrote:Hello,
<snip code example scraping a QOTD fromwww.mcgyver .com>
print out
**************
Since you have no control over spacing and line breaks in the input,
you can reformat using the textwrap module. *First replace all "\n"s
with " ", then use re.sub to replace multiple spaces with a single
space, then call textwrap.fill to reformat the line into lines up to
'n' characters long (I chose 50 in the sample below, but you can
choose any line length you like).
out = match.findall(h tml)
out = out[0].replace("\n"," ")
out = re.sub("\s+"," ",out)
print textwrap.fill(o ut,50)
-- Paul
One last try - .replace("\n"," ") is unnecessary, textwrap.fill takes
care of removing extra newlines already.
out = match.findall(h tml)
out = out[0]
out = re.sub("\s+"," ",out)
print textwrap.fill(o ut,50)
-- Paul
On May 19, 4:01 pm, Paul McGuire <pt...@austin.r r.comwrote:
On May 19, 4:54 am, kuratk...@kurat kull.com wrote:
Hello,
***************
import urllib2
import re
import string
import sys
url = "http://www.macgyver.co m/"
request = urllib2.Request (url)
opener = urllib2.build_o pener()
html = opener.open(req uest).read()
match = re.compile("<PR E>(.+)</PRE>", re.DOTALL)
out = match.findall(h tml)
print out
**************
This worked like a charm! :)
I used Python about a year ago and I have forgotten some of its
properties.
Thanks to both of you!
-kuratkull
>
I would like to print out string with formatting, but as I read, the
string is made into a raw string when using re.
How could I disable or bypass this?
I googled for an hour and couldn't find a solution.
Thank you in advance.
Change your print statement to:
print out[0]
-- Paul
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Silmar |
last post by:
Hi!
In my form I have table which cells contain input objects of type="text"
which initially are disabled. I would like to activate them by clicking on
them. However because input object does not support onClick event (or maybe
I am wrong?) I use onClick events of table cells. And it works as required
in IE 6. I click on the input object and the onClick event of the cell is
raised. But it does not work in Firefox (I have not yet checked...
|
by: Michael Conroy |
last post by:
Hi... Synposis...
Throws exception:
"Specified argument was out of the range of valid values."
Read on for the juicy tidbits.
MySimpleClassCol mscc=new MySimpleClassCol();
private void InitCombo()
{
|
by: Paul Sullivan |
last post by:
We are a state agency that views protected medical information via our
intranet. The screens even have privacy shields. Alarmingly, uses can
"Print" and "Save As" which destroys the protection of the health
information at the level we want.
QUESTION: Can we shut those off?? Any other suggestions??
Paul Sullivan
|
by: stephen |
last post by:
I have created an order form that users javascript to create a new html
document when the customers clicks the "print page" button.
Once the new document has been created it then prints the document and
closes it with the following code:
<body onload="window.print(); window.close();">
This works correctly (or at least the way I expect it to work under MS
Internet Explorer, but it cuases Netscape to "crash"
|
by: Viken Karaguesian |
last post by:
Hello all,
On occasion I want to open hyperlinks (images, etc.) in a new window. In the
past, I've used target="_blank" to open the link in a new window. However,
using the "target" attribute causes my pages to fail validation (strict
doctype). The validator says "There is no attribute 'target'.."
So...how do I open a link in a new window, without Javscript, and pass
strict validation?
| |
by: Claude |
last post by:
Hi,
I've designed my own form checking code for name, address, email, comment
box etc.
What my client keeps getting in his consumer feedback forms is "spam" from
companies who
repeatedly insert their hyperlinks in all fields, of course along with their
"hype"...
Is is possible with Javascript to refuse form contents whose strings contain
|
by: PraZ |
last post by:
Hi all.
Here is a simple code, which when compiled with gcc results in the
warning "incompatible pointer type" for arg 1, as expected. But this is
just what I want to do, because it makes it easy for me to handle the
single dimensional stream I have as a multidimensional array inside the
function func(). Now, I am just wondering if there is a way by which I
can disable this incompatible pointer type warning in gcc. Any
suggestions?
|
by: Jukka K. Korpela |
last post by:
Some time ago in this group, someone suggested that we should develop a
"different" user style sheet to demonstrate what a user style sheet or a
browser style sheet _could_ do. I guess the idea was that the style would be
rather different from common browser defaults, yet sensible and potentially
useful.
Partly for that reason, partly to demonstrate the idea that web page
rendering _could_ be different from what people are used to, I...
|
by: Koen Vossen |
last post by:
A project I'm currently working on uses Turbogears as a framework. I'd
like to interact with it using the tg-admin shell. We also use gettext's
_() function for internationalization. Now, this function is overwritten
in interactive mode, which causes annoying exceptions. Is it possible to
disable this behavior?
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |