Python Web 爬取
Thomas Laetsch
Data Scientist, NYU
Selector 与 Response:
xpath 和 css 方法,配合 extract 与 extract_first。xpath 方法的用法与 Selector 相同response.xpath( '//div/span[@class="bio"]' )
css 方法的用法与 Selector 相同response.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 在 response.url 变量中记录 URL。response.url
>>> 'http://www.DataCamp.com/courses/all'
response 可用 follow() 方法"跟进"新链接# next_url 是下一页要抓取的字符串路径
response.follow( next_url )
follow。Python Web 爬取