"qqq"> <li class="1"><a data-moreurl-dict='{"from":"top-nav-click-main","uid":"0"}' href="https://www.douban.com" target="_blank">豆瓣</a></li> <li class="on off"><a data-moreurl-dict='{"from":"top-nav-click-book","uid":"0"}' href="https://book.douban.com">读书</a></li> <li class="2"><a data-moreurl-dict='{"from":"top-nav-click-movie","uid":"0"}' href="https://movie.douban.com" target="_blank">电影</a></li> </ul> '''
doc = pq(data)
print(doc('li'))
url初始化
doc = pq(url='http://www.baidu.com')
print(doc('head'))
文件初始化
doc = pq(filename='demo.html')
print(doc('head'))
doc = pq(data)
items = doc('.qqq')
print(items)
print('-------------')
a = items.find('li')
print(a)
获取兄弟元素(不包括自己)
doc = pq(data)
li = doc.find('.on.off')
print(li.siblings())
doc = pq(data)
获取父元素
li = doc.find('.on')
print(li.parent())
doc = pq(data)
li = doc('li').items()
for i in li:
print(i)
print('---')
doc = pq(data)
a = doc('.on.off a')
print(a)
print(a.attr('href'))
print(a.attr.href)
print(a.text())
b = doc('.on.off')
print(b)
print(b.html())
doc = pq(data)
li = doc('.on.off')
print(li)
li.remove_class('on')
print(li)
li.add_class('WWW')
print(li)
li.attr('name','linkkk')
print(li)
li.css('font-size','14px')
print(li)
html = '''
<div class="wrap">
Hello world
<p>hahahahahahaahhahaha</p>
</div>
'''
doc = pq(html)
wrap = doc('.wrap')
print(wrap.text())
wrap.find('p').remove()
print(wrap.text())
上一篇: Keras 多线程下运行的问题