I’m using BeautifulSoup to parse a HTML page. I need to extract all URLs and sentences from a page that match a particular regex pattern. E.g.
http.*?example\.php
How can i do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you don’t care where the URLs are, in tags or in sentences, you could simply run a
re.findall()on the raw html you have. Of course, you’re gonna have to do better than that piddly little regex. Behold:(From http://regexlib.com/Search.aspx?k=URL, always a good resource for regex recipes).
Now for some code:
Update: Beefier regex.
Update: If you want to iterate over the matches, you can use
re.finditer: