python - Unable to create an appropriate CSS selector -


the problem python's css selectors.

i can't write selector in right way select item "last". tried with:

div.pager a:[text*='last'] 

elements within item lies:

<div class="pager"><a href="/search/1080p/" class="current">1</a> <a href="/search/1080p/t-23/">23</a> <a href="/search/1080p/t-255/">last</a> </div> 

it possible , answer is:

div.pager a:contains("last") 

and, here selector used within python script:

import requests lxml import html  main_link = "https://www.yify-torrent.org/search/1080p/" base_link = "https://www.yify-torrent.org"  def get_links(item_link):     response = requests.get(item_link).text     tree = html.fromstring(response)     next_page = tree.cssselect('div.pager a:contains("next")')[0].attrib["href"]     last_page = tree.cssselect('div.pager a:contains("last")')[0].attrib["href"]     print(base_link + next_page," ",base_link + last_page)  get_links(main_link) 

results:

https://www.yify-torrent.org/search/1080p/t-2/ https://www.yify-torrent.org/search/1080p/t-255/ 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -