Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76898
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: string encoding regex problem |
| Date | 2014-08-23 22:46 +0200 |
| Organization | 1&1 Internet AG |
| Message-ID | <ltaujl$3kj$1@online.de> (permalink) |
| References | <lsm8ic$j90$1@online.de> <roy-7B58DA.20484615082014@news.panix.com> <lsmeej$49n$1@online.de> <mailman.13048.1408179734.18130.python-list@python.org> |
[Multipart message — attachments visible in raw view] - view raw
Hi,
On 2014-08-16 09:01:57 +0000, Peter Otten said:
> Philipp Kraus wrote:
>
>> The code works till last week correctly, I don't change the pattern.
>
> Websites' contents and structure change sometimes.
>
>> My question is, can it be a problem with string encoding?
>
> Your regex is all-ascii. So an encoding problem is very unlikely.
>
>> found = re.search( "<a
>> href=\"/projects/boost/files/latest/download\?source=files\"
>> title=\"/boost/(.*)",
>> data)
>
>> Did I mask the question mark and quotes
>> correctly?
>
> Yes.
>
> A quick check...
>
>>>> data =
>>>> urllib.urlopen("http://sourceforge.net/projects/boost/files/boost/").read()
>>>>
>>>> re.compile("/projects/boost/files/latest/download\?source=files.*?>").findall(data)
>>>>
> ['/projects/boost/files/latest/download?source=files"
> title="/boost-docs/1.56.0/boost_1_56_pdf.7z: released on 2014-08-14
> 16:35:00 UTC">']
>
> ...reveals that the matching link has "/boost-docs/" in its title, so the
> site contents probably did change.
I have create a short script:
---------
#!/usr/bin/env python
import re, urllib2
def URLReader(url) :
f = urllib2.urlopen(url)
data = f.read()
f.close()
return data
print re.match( "\<small\ \>.*\<\/small\>",
URLReader("http://sourceforge.net/projects/boost/") )
---------
Within the data the string "<small>boost_1_56_0.tar.gz</small>" should
be machted, but I get always a None result on the re.match, re.search
returns also a None.
I have tested the regex under http://regex101.com/ with the HTML code
and on the page the regex is matched.
Can you help me please to fix the problem, I don't understand that the
match returns None
Thanks
Phil
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
string encoding regex problem Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-08-16 02:27 +0200
Re: string encoding regex problem Roy Smith <roy@panix.com> - 2014-08-15 20:48 -0400
Re: string encoding regex problem Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-08-16 04:08 +0200
Re: string encoding regex problem Roy Smith <roy@panix.com> - 2014-08-15 22:14 -0400
Re: string encoding regex problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-16 14:35 +1000
Re: string encoding regex problem Peter Otten <__peter__@web.de> - 2014-08-16 11:01 +0200
Re: string encoding regex problem Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-08-23 22:46 +0200
Re: string encoding regex problem Peter Otten <__peter__@web.de> - 2014-08-23 23:13 +0200
csiph-web