I'm writting a spider, and I want to know which link is mean "next page",so I need to get the element by the value = "next page", and then get the link. It's not only include one tag, it's a whole html source code, and I want to get the specific link.
if I want to get a element like
`<a href="http://*****">..</a>`
I can use
`'a[href^="http"]'`
And I try
`'a[text="value"]'`
Try 'Contains':
from pyquery import PyQuery as pq
doc = pq("<html><body><a href='https://stackoverflow.com'>Next page</a><p>...Next time...</p></body></html>")
el = doc('a:Contains("Next")')
el.text() # 'Next page'
el.attr['href'] # 'https://stackoverflow.com'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With