Scrapy练习笔记-2

继续-1的天气爬虫
先爬后取
在weather文件夹下出现两张网页的源代码
之前顶了item容器,现在从两个网页中的源代码中找出
title
link
desc
分别保存提取出来。
在cmd命令中

C:\D\mypython\weather>scrapy shell 
"http://www.weather.com.cn/weather/101190401.shtml"

将它载入之后就可以进行操作了
可以得到response的回应

>>> response.body

得到网页的代码

>>> response.headers

网页的头
从body中找出
title
link
desc
用XPath找title

>>>response.xpath('//title/text()').extract()   #将得到的title字符串化
['【苏州天气】苏州天气预报,蓝天,蓝天预报,雾霾,雾霾消散,天气预报一周,天气预报15天查询']

找到原网页中有用的信息

>>> sel.xpath('//ul/li/text()')

猜你喜欢

转载自blog.csdn.net/weixin_43139613/article/details/82768997