<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>
如何使用 PyQuery 提取消息?
from pyquery import PyQuery as pq
d = pq('http://www.somesite.com')
我试过了:
d('#ui-accordion-accordion-panel-0').text()
d('ui-accordion-content.ui-helper-reset.ui-widget-content.ui-corner-bottom.ui-accordion-content-active').text()
d('#accordion#ui-accordion-accordion-panel-0').text()
如果我使用d('#accordion').text()
,div
则显示其下的每个文本,所以我不明白为什么我的第一个示例没有返回任何内容。