python selenium - how to read/store a text on a webpage -


https://gyazo.com/6f590c16fc078a0cd90fa2b0d4343d3c can see want script read text "29 dage" how locate selenium. can see underclass="dbalisting listing lastlisting"and 4th want python read. how shall that?

selenium provides function find_element_by_css_selector() locates first element based on provided css selector. (there's multi-item variant, find_elements_by_css_selector(), returns list of matching elements.)

text = driver.find_element_by_css_selector('.dbalisting.listing.lastlisting > td:nth-child(4) > span').text 

css main way of styling html. css selectors how elements chosen different styling. these selector rules used other tools well-known way of selecting elements.

. indicates class. (there # ids, not used here; nothing element names, used td , span; , : or :: psuedo-selectors.) tells system want elements class.

> relationship operator meaning "parent/child relationship".

(space technically relationship operator meaning "ancestor/descendant relationship". it's used readability when adjacent other relationship operators. it's common in css not used relationship operator here.)

:nth-child() pseudo-selector meaning "siblings these indexes". used above, means "4th sibling". basic form of operator :nth-child(an+b). an+b (as in: a times n plus b) formula indicating items out of collection of siblings selected a , b integers , default 0. n integer handled css selector engine; can considered "any integer". elements start on index 1. parts can dropped formula filled out defaults. long form of :nth-child(4) :nth-child(0n+4). in english read like: "sibling elements index matches formula an+b n integer, a [supplied integer] , b [supplied integer]." can read more selector here , here.

altogether have instructs:

  1. get elements have class "dbalisting"
  2. ... , have class "listing"
  3. ... , have class "lastlisting"
  4. get children of these elements
  5. ... td elements
  6. ... , fourth child of parent
  7. get children of elements
  8. ... span elements

css selectors cheatsheat has quick rundown of various selectors.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -