Re: [问题] pyquery

楼主: poototo (poototo)   2021-05-04 16:01:00
from pyquery import PyQuery as pq
#
html = '''
<html>
<a data-v-54b96320="" href="/magic/11320" target="_blank"
class="m-card-s">
<a data-v-54b96320="" href="/magic/11320aaa" target="_blank"
class="m-card-s">
<a data-v-54b96320="" href="/magic/11320bbb" target="_blank"
class="m-card-s">
</html>
'''
doc = pq(html)
all_a = doc.find('a')
for a in all_a:
a = pq(a)
href = a.attr('href')
print(href)
※ 引述《bchoice (choice)》之铭言:
: 我用pyquery后
: 该怎么撷取 href="/magic/11320 这段文字
: <a data-v-54b96320="" href="/magic/11320" target="_blank" class="m-card-s">
: 感谢各位前辈
: doc = pq(html)
: a = doc('a')
: for item in a.items():
: href = item.attr('href')
: print (href)
: 我的程式是这样,该怎么改
: 感谢
作者: bchoice (choice)   2021-05-04 21:35:00
原来是这样!太感谢了

Links booklink

Contact Us: admin [ a t ] ucptt.com