新聞中心
1、引入pyquery,取別名為pq。然后聲明長HTML字符串,并將其作為參數(shù)傳遞給PyQuery。

成都創(chuàng)新互聯(lián)公司提供成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì),成都品牌網(wǎng)站建設(shè),一元廣告等致力于企業(yè)網(wǎng)站建設(shè)與公司網(wǎng)站制作,十年的網(wǎng)站開發(fā)和建站經(jīng)驗(yàn),助力企業(yè)信息化建設(shè),成功案例突破數(shù)千家,是您實(shí)現(xiàn)網(wǎng)站建設(shè)的好選擇.
html = '''first itemsecond itemthird itemfourth itemfifth item'''
from pyquery import PyQuery as pq
doc = pq(html)
print(doc('li'))
2、URL傳入網(wǎng)頁,只需指定url參數(shù)。
from pyquery import PyQuery as pq
doc = pq(url='http://cuiqingcai.com')
print(doc('title'))
3、傳輸本地文件名,將參數(shù)指定為filename。
from pyquery import PyQuery as pq
doc = pq(filename='demo.html')
print(doc('li'))
這里需要本地HTML文件demo.html,內(nèi)容是待分析的HTML字符串。這樣會(huì)先讀本地文件內(nèi)容,然后以字符串的形式傳遞給PyQuery。
以上就是python中pyquery初始化的方法,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
網(wǎng)頁標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中pyquery初始化的方法
URL網(wǎng)址:http://www.dlmjj.cn/article/coicgod.html


咨詢
建站咨詢
