I need a regex in python to find a links html in a larger set of html.
so if I have:
<ul class="something">
<li id="li_id">
<a href="#" title="myurl">URL Text</a>
</li>
</ul>
I would get back:
<a href="#" title="myurl">URL Text</a>
I’d like to do it with a regex and not beautifulsoup or something similar to that. Does anyone have a snippet laying around I could use for this?
Thanks
Soup is good for you:
There are many arguments you can pass to the
findAllmethod; more here. The one line below will get you started by returning a list of all links matching some conditions.Edit: based on OP’s comment, added info included:
So let’s say you’re interested in only tags within list elements of a certain class
<li class="li_class">. You could do something like this:Soup recipe: