我正尝试在Python上使用Selenium在HTML之下抓取,但我无法抓取文本
<div class="tt">
<ul style="list-style-type:none" id="abs2">
<li>
Funeral rites have considerably been transformed as family structure has shifted to nuclear family and urbanization has been expedited. People came to consign more and more the rites commitment to funeral service providers and the ritual process itsel...
</li>
<li style="display:none">
Funeral rites have considerably been transformed as family structure has shifted to nuclear family and urbanization has been expedited. People came to consign more and more the rites commitment to funeral service providers and the ritual process itself became a lot modernized and commercialized at the same time. As a result, the cost spent for family rites each year has increaseda lot.<br>Today, the number of single family is on the increase. If this trend lasts continuously for so long, the cost for funeral rites will become a heavy burden to the bereaved in near future.
</li>
</ul>
</div>
我无法通过单击下一页来成功进行爬网。请帮我。这是我的代码:
a = driver.find_element_by_css_selector('#abs1 > li:nth-child(2)').get_attribute('style')
print(a)
“ print(a)”的输出如下;
显示:无;
答案 0 :(得分:0)
您正在打印 style 属性。您是否尝试过text
?
a = driver.find_element_by_css_selector('#abs2 > li:nth-child(2)').text
print(a)
如果这不起作用,请尝试获取innerText
,如下所示:
a = driver.find_element_by_css_selector('#abs2 > li:nth-child(2)').get_attribute('innerText')
print(a)