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
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to