Issue
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
.
Here is how I did it using Beautiful Soup version 4:
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 do I get only 133
?
Solution
Since you only want the first element in the iterator, addressing it directly should work:
first = inpu.select('input')[0].get('value')
print(first)
Answered By - MatsLindh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.