Beautifulsoup print value in div [duplicate]












0
















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!










share|improve this question













marked as duplicate by Andersson python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

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.























    0
















    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!










    share|improve this question













    marked as duplicate by Andersson python
    Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

    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.





















      0












      0








      0









      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!










      share|improve this question















      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 13:15









      ArronArron

      94




      94




      marked as duplicate by Andersson python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      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 python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      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.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          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'))





          share|improve this answer
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            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'))





            share|improve this answer






























              0














              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'))





              share|improve this answer




























                0












                0








                0







                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'))





                share|improve this answer















                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'))






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 '18 at 13:34

























                answered Nov 21 '18 at 13:28









                QHarrQHarr

                35.4k82144




                35.4k82144

















                    Popular posts from this blog

                    How to send String Array data to Server using php in android

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                    Is anime1.com a legal site for watching anime?