欢迎加入python学习交流群 667279387
爬虫学习
爬虫学习(一)—爬取电影天堂下载链接
爬虫学习(二)–爬取360应用市场app信息
代码环境:windows10, python 3.5
主要用的软件包:SQLAlchemy,re
初学爬虫,没有使用scrapy框架,而是自己简单打了一个框架。代码里面也没有考虑记录日志以及错误处理等方面的内容,只是能简单工作。如果需要可以在此源码的基础上面进行修改。源码下载地址在文章末尾。
本次抓取主要抓取了app名字,下载次数,评分,开发公司,最新版本号,更新时间。
先打开一个具体的软件页面进行查看网页源码
http://zhushou.360.cn/detail/index/soft_id/77208
下面是截取含有具体信息的两个网页源码的片段。
<h2 id="app-name"><span title="360手机卫士-一键连免费wifi">360手机卫士-一键连免费wi...span><cite class="verify_tag">cite><cite class="white_tag">cite>h2>
<div class="pf"> <span class="s-1 js-votepanel">8.8<em>分em>span>
<span class="s-2"><a href="#comment-list" id="comment-num"><span class="js-comments review-count-all" style="margin:0;">0span>条评价a>span>
<span class="s-3">下载:187373万次span>
<span class="s-3">15.82Mspan>
<td width="50%"><strong>作者:strong>北京奇虎科技有限公司td>
<td width="50%"><strong>更新时间:strong>2017-09-13td>
<td><strong>版本:strong>7.7.4td>
<td><strong>系统:strong>Android 4.0.3以上td> <td colspan="2"><strong>语言:strong>中文td>
本次解析也没有xpath解析,而是直接用正则来匹配。下面是正则匹配时用到的代码。
r_name = re.compile(u"(.*?)_360手机助手 ", re.DOTALL)
r_download_num = re.compile(u'下载:(.*?)次', re.DOTALL)
r_score = re.compile(u'(.*?)分', re.DOTALL)
r_author = re.compile(u"作者:(.*?)", re.DOTALL)
r_version = re.compile(u"版本:(.*?)