Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python BeautifulSoup get specific element

if i have an html code like this

<div class="new_info_next">
     <input type="hidden" value="133" id="new_id" class="new_id">
     <input type="hidden" value="0" id="default_pe" class="default_pe">
</div>

and i want to get only 133 in input the first line i try this code using BeautifulSoup4

info = soup.find_all("div", {"class": "new_info_next"})
for inpu in info:
    for inpu1 in inpu.select('input'):
         print inpu1 .get('value')

but the output was

133
0

how to get only 133

like image 363
Aymen Derradji Avatar asked Feb 08 '23 10:02

Aymen Derradji


1 Answers

use soup.find()

by default it will get you the first element matching, so you could do:

info = soup.find("div", {"class": "new_info_next"})

and info.get('value') should be 133

like image 119
northsideknight Avatar answered Feb 12 '23 12:02

northsideknight