推 bchoice: 原來是這樣!太感謝了 05/04 21:35
※ 引述《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)
: 我的程式是這樣,該怎麼改
: 感謝
--
You love playing with that.
You love playing with all your stuffed animals.
You love your mommy,your daddy,your nature pajamas.
You love everything,don't you?
Yeah,
You know what,buddy?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.138.25.226 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1620115263.A.F15.html
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)