skip to Main Content

What’s the js alternative of this python script:

from bs4 import BeautifulSoup as bs
import requests

page = requests.get(url).text

soup = bs(page)
items = soup.findAll('li')

I’ve searched DOM Parser documentation but i can’t find anything like findall().

Can someone help me?

2

Answers


  1. Try Doing this
    items = soup.findAll(‘li’, class=’ClassNameofthatparticularli’ )

    I hope this might work for you. If not ask me again.

    Login or Signup to reply.
  2. fetch(url).then(res => res.text()).then(page => {
      const parser = new DOMParser()
      const doc = parser.parseFromString(page, "text/html")
      const items = doc.querySelectorAll('li')
    })
    

    You can call all the method supported by the Document interface on the doc constant in this code snippet. Here I used the querySelectorAll method that returns a NodeList containing all li elements in the document.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search