Beautifulsoup print value in div [duplicate]
This question already has an answer here:
Extracting an attribute value with beautifulsoup
5 answers
Im trying to print the text after the value= field so far the output looks like this.
<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>
My code looks like this.
soup = BeautifulSoup(html, 'lxml')
contact = soup.find('div', {"class": "controls"})
print(contact)
How can I print the text following the "value=" so just John Smith
Thanks!
python selenium beautifulsoup screen-scraping
marked as duplicate by Andersson
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 13:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Extracting an attribute value with beautifulsoup
5 answers
Im trying to print the text after the value= field so far the output looks like this.
<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>
My code looks like this.
soup = BeautifulSoup(html, 'lxml')
contact = soup.find('div', {"class": "controls"})
print(contact)
How can I print the text following the "value=" so just John Smith
Thanks!
python selenium beautifulsoup screen-scraping
marked as duplicate by Andersson
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 13:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Extracting an attribute value with beautifulsoup
5 answers
Im trying to print the text after the value= field so far the output looks like this.
<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>
My code looks like this.
soup = BeautifulSoup(html, 'lxml')
contact = soup.find('div', {"class": "controls"})
print(contact)
How can I print the text following the "value=" so just John Smith
Thanks!
python selenium beautifulsoup screen-scraping
This question already has an answer here:
Extracting an attribute value with beautifulsoup
5 answers
Im trying to print the text after the value= field so far the output looks like this.
<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>
My code looks like this.
soup = BeautifulSoup(html, 'lxml')
contact = soup.find('div', {"class": "controls"})
print(contact)
How can I print the text following the "value=" so just John Smith
Thanks!
This question already has an answer here:
Extracting an attribute value with beautifulsoup
5 answers
python selenium beautifulsoup screen-scraping
python selenium beautifulsoup screen-scraping
asked Nov 21 '18 at 13:15
ArronArron
94
94
marked as duplicate by Andersson
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 13:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Andersson
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 13:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It is faster to use an id when using CSS selectors and should be your first choice when available (And truly unique on page). You can then use .get to access the value of the value attribute of the matched element.
from bs4 import BeautifulSoup
html = '<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>'
soup = BeautifulSoup(html, "lxml")
print(soup.select_one('#client_appbundle_prospecttype_name').get('value'))
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is faster to use an id when using CSS selectors and should be your first choice when available (And truly unique on page). You can then use .get to access the value of the value attribute of the matched element.
from bs4 import BeautifulSoup
html = '<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>'
soup = BeautifulSoup(html, "lxml")
print(soup.select_one('#client_appbundle_prospecttype_name').get('value'))
add a comment |
It is faster to use an id when using CSS selectors and should be your first choice when available (And truly unique on page). You can then use .get to access the value of the value attribute of the matched element.
from bs4 import BeautifulSoup
html = '<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>'
soup = BeautifulSoup(html, "lxml")
print(soup.select_one('#client_appbundle_prospecttype_name').get('value'))
add a comment |
It is faster to use an id when using CSS selectors and should be your first choice when available (And truly unique on page). You can then use .get to access the value of the value attribute of the matched element.
from bs4 import BeautifulSoup
html = '<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>'
soup = BeautifulSoup(html, "lxml")
print(soup.select_one('#client_appbundle_prospecttype_name').get('value'))
It is faster to use an id when using CSS selectors and should be your first choice when available (And truly unique on page). You can then use .get to access the value of the value attribute of the matched element.
from bs4 import BeautifulSoup
html = '<div class="controls"><input class="span12 text-bound" id="client_appbundle_prospecttype_name" maxlength="100" name="client_appbundle_prospecttype[name]" required="required" type="text" value="John Smith"/></div>'
soup = BeautifulSoup(html, "lxml")
print(soup.select_one('#client_appbundle_prospecttype_name').get('value'))
edited Nov 21 '18 at 13:34
answered Nov 21 '18 at 13:28
QHarrQHarr
35.4k82144
35.4k82144
add a comment |
add a comment |