pythonpyquery

How can I extract the message?


<div style="width: 400px;" id="accordion" class="ui-accordion ui-widget ui-helper-reset" role="tablist">
  <h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-accordion-header-active ui-state-active ui-corner-top" role="tab" id="ui-accordion-accordion-header-0" aria-controls="ui-accordion-accordion-panel-0" aria-selected="true" tabindex="0"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span>
                    Description</h3>
  <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active" style="display: block;" id="ui-accordion-accordion-panel-0" aria-labelledby="ui-accordion-accordion-header-0" role="tabpanel" aria-expanded="true" aria-hidden="false">
                    this is the message I want to extract
  </div>
</div>

How can I extract the message using PyQuery?

from pyquery import PyQuery as pq
d = pq('http://www.somesite.com')

I've tried:

If I use d('#accordion').text(), every text under that divis displayed, so I don't understand why my first example doesn't return anything.


Solution

  • Finally I managed to extract it.

    d('#accordion').find('div').eq(0).text()