เส้นทาง XPath ที่ไม่ธรรมดา

Web Scraping ด้วย Python

Thomas Laetsch

Data Scientist, NYU

(At)tribute

  • @ แทน "attribute"
    • @class
    • @id
    • @href
Web Scraping ด้วย Python

วงเล็บและ Attribute

xpathattr.png

Web Scraping ด้วย Python

วงเล็บและ Attribute

xpathattr_div_p1.png

xpath = '//p[@class="class-1"]'
Web Scraping ด้วย Python

วงเล็บและ Attribute

xpathattr_div.png

xpath = '//*[@id="uid"]'
Web Scraping ด้วย Python

วงเล็บและ Attribute

xpathattr_div_astc2.png

xpath = '//div[@id="uid"]/p[2]'
Web Scraping ด้วย Python

การใช้ contains

รูปแบบ contains ใน XPath:

contains( @attri-name, "string-expr" )

Web Scraping ด้วย Python

ใช้ contains

xpath = '//*[contains(@class,"class-1")]'

ClassSelection-Xpath-contains.png

Web Scraping ด้วย Python

ใช้ contains

xpath = '//*[@class="class-1"]'

ClassSelection-Xpath-eq.png

Web Scraping ด้วย Python

ดึง Class

xpathattr_div_astc2.png

xpath = '/html/body/div/p[2]'
Web Scraping ด้วย Python

ดึง Class

xpathattr_div_p2-class.png

xpath = '/html/body/div/p[2]/@class'
Web Scraping ด้วย Python

สิ้นสุดเส้นทาง

Web Scraping ด้วย Python

Preparing Video For Download...