英文:
how to get element with xpath by attribute value
问题
从此页面尝试获取下一页箭头链接。然而,response.selector.xpath('//a[aria-label="Next page"]')
返回的是[]。帮助!
我能够用response.selector.xpath('//*[contains(@class, "Pagination_arrowItem")]/a')[1].attrib['href']
来解决,但是如果是第一页并且只显示一个箭头,则会遇到问题。
英文:
trying to get the next page arrow link from this page. however
response.selector.xpath('//a[aria-label="Next page"]')
yields []. help!
I was able to solve it with response.selector.xpath('//*[contains(@class, "Pagination_arrowItem")]/a')[1].attrib['href']
but then run into an issue if it's the firts page and only one arrow is shown.
答案1
得分: 1
你应该能够通过以下方式获取它:
response.selector.xpath('//a[@data-e2e-test="pagination-next"]')
更多信息,请查看Scrapy文档。
英文:
You should be able to get it with:
response.selector.xpath('//a[@data-e2e-test="pagination-next"]')
See Scrapy documentation for more.
答案2
得分: 1
Since the anker itself is using a workable @data-e2e-test attribute, its name seems a bit temporary. Therefore you also could use:
// *[starts-with(@class, "Pagination_container")]/div[position()=last()]/a
英文:
Since the anker itself is using a workable @data-e2e-test attribute, its name seems a bit temporary. Therefore you also could use:
//*[starts-with(@class,"Pagination_container")]/div[position()=last()]/a
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论