Question:
I’m trying to get the links in all li tags under the ul tagHTML code:
Answer:
You can usefind
to find the ul
in the chapter list. And then find_all
to find the list items in the ul
. Finally, use find_all
again to find the links in each list item and print the URL. Details of these two methods can be found in find and find_all method documentation on bs4. You can use the get_text()
after searching by the class chapternum
on each link to get the link’s text like Chapter 1
. Searching by class be found in bs4 documentation for searching element by class(Updated) Code:
If you have better answer, please add a comment about this, thank you!