python中PyQuery庫(kù)用法分享
PyQuery庫(kù)就是python中的一個(gè)解析庫(kù)。作用十分強(qiáng)大,使用上也是相當(dāng)?shù)撵`活,能夠?qū)崿F(xiàn)初始化字符串、初始化 HTML 文件、初始化請(qǐng)求響應(yīng)等多種場(chǎng)景,另外,本身中的CSS選擇器,也是經(jīng)常被大家使用的對(duì)象,結(jié)合以上的大致內(nèi)容總結(jié),接下來(lái),我們一起詳細(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.intensediesel.com/bcjs/link2.html' rel='external nofollow' >second item</a></li><li class='item-0 active'><a href='http://www.intensediesel.com/bcjs/link3.html' rel='external nofollow' ><span class='bold'>third item</span></a></li><li class='item-1 active'><a href='http://www.intensediesel.com/bcjs/link4.html' rel='external nofollow' >fourth item</a></li><li class='item-0'><a href='http://www.intensediesel.com/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庫(kù)用法分享的文章就介紹到這了,更多相關(guān)python中PyQuery庫(kù)是什么內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 告別AJAX實(shí)現(xiàn)無(wú)刷新提交表單2. 小技巧處理div內(nèi)容溢出3. PHP循環(huán)與分支知識(shí)點(diǎn)梳理4. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案5. jsp實(shí)現(xiàn)簡(jiǎn)單用戶7天內(nèi)免登錄6. JavaWeb Servlet中url-pattern的使用7. 使用XSL將XML文檔中的CDATA注釋輸出為HTML文本8. XML入門的常見問(wèn)題(一)9. chat.asp聊天程序的編寫方法10. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向
