python中PyQuery庫用法分享
PyQuery庫就是python中的一個解析庫。作用十分強大,使用上也是相當(dāng)?shù)撵`活,能夠?qū)崿F(xiàn)初始化字符串、初始化 HTML 文件、初始化請求響應(yīng)等多種場景,另外,本身中的CSS選擇器,也是經(jīng)常被大家使用的對象,結(jié)合以上的大致內(nèi)容總結(jié),接下來,我們一起詳細(xì)的了解使用內(nèi)容。
安裝:
>>> pip3 install pyquery
引用方法:
from pyquery import PyQuery as pq
CSS選擇器:
from pyquery import PyQuery as pqhtml = ’’’<div id='container'><ul class='list'><li class='item-0'>first item</li><li class='item-1'><a href='http://www.leifengta.com.cn/bcjs/link2.html' rel='external nofollow' >second item</a></li><li class='item-0 active'><a href='http://www.leifengta.com.cn/bcjs/link3.html' rel='external nofollow' ><span class='bold'>third item</span></a></li><li class='item-1 active'><a href='http://www.leifengta.com.cn/bcjs/link4.html' rel='external nofollow' >fourth item</a></li><li class='item-0'><a href='http://www.leifengta.com.cn/bcjs/link5.html' rel='external nofollow' >fifth item</a></li></ul></div>’’’doc=pq(html)print(doc('#container .list li'))
輸出結(jié)果:

到此這篇關(guān)于python中PyQuery庫用法分享的文章就介紹到這了,更多相關(guān)python中PyQuery庫是什么內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 理解PHP5中static和const關(guān)鍵字2. Android table布局開發(fā)實現(xiàn)簡單計算器3. python 代碼實現(xiàn)k-means聚類分析的思路(不使用現(xiàn)成聚類庫)4. IntelliJ IDEA安裝插件的方法步驟5. Java如何基于反射機制獲取不同的類6. php模擬實現(xiàn)斗地主發(fā)牌7. Vue封裝一個TodoList的案例與瀏覽器本地緩存的應(yīng)用實現(xiàn)8. Android 在 res/layout 文件夾 下創(chuàng)建一個 子文件夾實例9. PHP安全-命令注入10. Vuex localStorage的具體使用

網(wǎng)公網(wǎng)安備