Web Scraping với Python
Thomas Laetsch
Data Scientist, NYU
Selector vs Response:
Response có đủ công cụ đã học với Selector:xpath, css kèm theo extract và extract_first.Response cũng lưu lại URL nguồn nơi tải HTML.Response giúp chuyển từ trang này sang trang khác để "thu thập" trên web.xpath hoạt động như một Selectorresponse.xpath( '//div/span[@class="bio"]' )
css hoạt động như một 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 lưu URL trong biến response.url.response.url
>>> 'http://www.DataCamp.com/courses/all'
response cho phép "theo" liên kết mới với phương thức follow()# next_url là chuỗi đường dẫn của URL kế tiếp cần thu thập
response.follow( next_url )
follow sau.Web Scraping với Python