• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: problem finding links in all li tag under ul tag

Resolved: problem finding links in all li tag under ul tag

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m trying to get the links in all li tags under the ul tag
HTML code:
The code I wrote:
When I try to print the li tags links, it gives the following error:

Answer:

You can use find 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:
Output:
References:
  • find and find_all method documentation on bs4
  • bs4 documentation for searching element by class

If you have better answer, please add a comment about this, thank you!

python python-requests web-scraping
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: CMake path for python3 libraries doesn’t change (windows 10)

24/03/2023

Resolved: GLMM with quasi-Poisson distribution

24/03/2023

Resolved: Is it possible to do custom preinstall scripts for npm from which one is run depending on the environment?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.