本文的案例会在parse方法中通过response参数设置XPath,然后从HTML代码中过滤出我们感兴趣的信息,最后将这些信息输出到PyCharm的Console中。
下面的例子通过XPath过滤出指定页面的博文列表,并利用Beautiful Soup对博文的相关信息进一步过滤,最后在Console中输出博文标题等信息。
import scrapy
from bs4 import *
class BlogSpider(scrapy.Spider):
name = 'BlogSpider'
start_urls = [
'https://geekori.com/blogsCenter.php?uid=geekori'
]
def parse(self,response):
# 过滤出指定页面所有的博文
sectionList = response.xpath('//*[@id="all"]/div[1]/section').extract()
# 对博文列表进行迭代
fo