Веб-скрапинг на Python
Thomas Laetsch
Data Scientist, NYU
Selector и Response:
xpath и css в сочетании с методами extract и extract_first.xpath работает как Selectorresponse.xpath( '//div/span[@class="bio"]' )
css работает как Selectorresponse.css( 'div > span.bio' )
response.xpath('//div').css('span.bio')
response.xpath('//div').css('span.bio').extract()
response.xpath('//div').css('span.bio').extract_first()
response хранит URL в переменной response url.response.url
>>> 'http://www.DataCamp.com/courses/all'
response позволяет «следовать» по новой ссылке с помощью метода follow()# next_url is the string path of the next url we want to scrape
response.follow( next_url )
follow мы поговорим позже.Веб-скрапинг на Python