Navigazione XPath

Web Scraping in Python

Thomas Laetsch

Data Scientist, NYU

Slash e parentesi

  • Una singola slash / guarda avanti di una generazione
  • Doppia slash // guarda avanti tutte le generazioni future
  • Le parentesi quadre [] restringono a elementi specifici
Web Scraping in Python

Con parentesi o senza?

Selettore body in XPath

xpath = '/html/body'
xpath = '/html[1]/body[1]'
  • Danno la stessa selezione
Web Scraping in Python

Un body pieno di p

xpath = '/html/body/p'

Selettore p nel body

Web Scraping in Python

Div e p

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

Selettore p dentro div

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

Selettore secondo p nel div

Web Scraping in Python

Doppie barre con parentesi

xpath = '//p'

Selettore p in XPath

xpath = '//p[1]'

Selettore primo p nel body

Web Scraping in Python

Il jolly

xpath = '/html/body/*'

Selettore body con asterisco

  • L’asterisco * è il "jolly"
Web Scraping in Python

Xposé

Web Scraping in Python

Preparing Video For Download...