Python ile Web Scraping
Thomas Laetsch
Data Scientist, NYU
/ yerine > kullanın/html/body/divhtml > body > div// boşlukla değiştirilir//div/span//pdiv > span p[N] yerine :nth-of-type(N) kullanın//div/p[2]div > p:nth-of-type(2)XPATH
xpath = '/html/body//div/p[2]'
CSS
css = 'html > body div > p:nth-of-type(2)'
. kullanınp.class-1 class-1 sınıfındaki tüm paragraf öğelerini seçer# kullanındiv#uid id’si uid olan div öğesini seçerclass1 sınıfındaki paragraf öğelerini seçin:
css_locator = 'div#uid > p.class1'
Sınıf özniteliği class1 olan tüm öğeleri seçin:
css_locator = '.class1'
css = '.class1'

xpath = '//*[@class="class1"]'

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

from scrapy import Selector
html = '''
<html>
<body>
<div class="hello datacamp">
<p>Hello World!</p>
</div>
<p>Enjoy DataCamp!</p>
</body>
</html>
'''
sel = Selector( text = html )
>>> sel.css("div > p")
çıktı: [<Selector xpath='...' data='<p>Hello World!</p>'>]
>>> sel.css("div > p").extract()
çıktı: [ '<p>Hello World!</p>' ]
Python ile Web Scraping