string encoding regex problem
Peter Otten
__peter__ at web.de
Sat Aug 16 05:01:57 EDT 2014
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.
More information about the Python-list
mailing list