Issue
<ul class="main">
<li>
<a href="/1.html"></a>
</li>
<a href="/2.html"></a>
<li>
<a href="/3.html"></a>
</li>
</ul>
<ul class="main2">
<li>
<a href="/1.mp4"></a>
</li>
<a href="/2.mp4"></a>
<li>
<a href="/3.mp4"></a>
</li>
</ul>
as i can't use soup.findAll("ul",class_="main").ul.a["href=True"]
i want output like from main class
["/1.html","/2.html","/3.html"]
Solution
You can use CSS selector .main a
-> this will find all <a>
tags under tag with class="main"
:
print([a['href'] for a in soup.select('.main a')])
Prints:
['/1.html', '/2.html', '/3.html']
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.