Reputation: 121
I want to search if there is /[some names]/unfollow
in a webpage. And I have very little experience on regular expressions. This is what I worked for now.
import urllib
import re
page = urllib.urlopen('http://www.domain.com').read()
results = re.findall('/[\w]*/unfollow', page)
for i in results:
print i
But the code above not printing anything. Am I doing it wrong? If so, I really need help from you guys
Thanks
Upvotes: 0
Views: 2187
Reputation: 174706
Your findall function should be,
results = re.findall(r'\/[^\/]*\/unfollow', page)
It will findall all the strings which are in /some names/unfollow
format.
Explanation:
\/
Matches a literal /
symbol.[^\/]*
Matches any character not of /
zero or more times.\/unfollow
Matches the string /unfollow
Upvotes: 1