Navigare XPath

Web Scraping în Python

Thomas Laetsch

Data Scientist, NYU

Slash-uri și paranteze pătrate

  • Slash-ul simplu / avansează o generație
  • Slash-ul dublu // avansează toate generațiile următoare
  • Parantezele pătrate [] permit selectarea unor elemente specifice
Web Scraping în Python

Cu sau fără paranteze pătrate

Selectare body cu xpath

xpath = '/html/body'
xpath = '/html[1]/body[1]'
  • Returnează aceeași selecție
Web Scraping în Python

Elementele p din body

xpath = '/html/body/p'

Selectare p din body cu xpath

Web Scraping în Python

Elementele p din div

xpath = '/html/body/div/p'

Selectare p din div cu xpath

xpath = '/html/body/div/p[2]'

Selectare al doilea p din div cu xpath

Web Scraping în Python

Slash dublu și paranteze pătrate

xpath = '//p'

Selectare p cu xpath

xpath = '//p[1]'

Selectare primul p din body

Web Scraping în Python

Wildcard-ul

xpath = '/html/body/*'

Selectare toate elementele din body

  • Asteriscul * este „wildcard-ul"
Web Scraping în Python

Xposé

Web Scraping în Python

Preparing Video For Download...