I am trying to extract list of data from drop down box. When I checked the html source, it is nested in this div data-app as below:
<div data-app="true" id="app" class="application application--light"></div>
Tried using beautifulsoup but can't seem to extract any relevant information. Anyone can advise whether it's possible to extract information from div data-app and what method to use?
Thank you!
CodePudding user response:
Yes, You can extract data from div using those approch
Using pure JavaScript
document.querySelector("div").dataset.app
Using jQuery
$("div").data("app");
CodePudding user response:
You can access a tag’s attributes by treating the tag like a dictionary - Select your element and call the attribut:
soup.select_one('#app')['data-app']
Example
from bs4 import BeautifulSoup as Soup
html='''
<div data-app="true" id="app" >text</div>
'''
soup = Soup(html, features="html.parser")
print(soup.select_one('#app')['data-app'])
Output
true