網(wǎng)站首頁 編程語言 正文
When we use XPath to crawl web pages, we may encounter such a problem: the list printed using the text method is empty, which?can be caused by non specified direct content.
attention:text() method can only get direct content, string(.) can get whole content and then?composed?in?one?whole?string?returned?to?the?caller.
solution:
<div class="bottom">
<ul class="unstyled">
<li><a href="monthdata.php?city=北京">北京</a></li>
<li><a href="monthdata.php?city=上海">上海</a></li>
<li><a href="monthdata.php?city=廣州">廣州</a></li>
<li><a href="monthdata.php?city=深圳">深圳</a></li>
<li><a href="monthdata.php?city=杭州">杭州</a></li>
<li><a href="monthdata.php?city=天津">天津</a></li>
<li><a href="monthdata.php?city=成都">成都</a></li>
<li><a href="monthdata.php?city=南京">南京</a></li>
<li><a href="monthdata.php?city=西安">西安</a></li>
<li><a href="monthdata.php?city=武漢">武漢</a></li>
</ul>
</div>
# 第一種方法
li_list = tree.xpath('//div[@class="bottom"]/ul/li/a/text()')
# 第二種方法
li_list = tree.xpath('//div[@class="bottom"]/ul/li//text()')
原文鏈接:https://blog.csdn.net/qq_61177928/article/details/122870506
相關(guān)推薦
- 2022-10-07 Docker容器操作方法詳解_docker
- 2023-07-07 electron 運行以及打包超時解決方法
- 2022-04-14 如何解決error: failed to push some refs to ‘xxx(遠程庫)‘
- 2022-07-29 Linux中文件的基本屬性介紹_linux shell
- 2022-04-15 C語言各種操作符透徹理解下篇_C 語言
- 2022-11-23 詳解React?Native中如何使用自定義的引用路徑_React
- 2022-07-13 Python字符串中如何去除數(shù)字之間的逗號_python
- 2022-08-05 python內(nèi)置模塊之上下文管理contextlib_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支