Python_crawling <li style="display: none;">
Python_crawling <li style="display: none;">
我正在尝试在 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)" 的输出如下;
显示:none;
您正在打印 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)
我正在尝试在 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)" 的输出如下;
显示:none;
您正在打印 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)