Python 爬虫简单实战之CSDN
2017-07-16 14:57
603 查看
此文仅是分享 <(o゜▽゜)o☆[BINGO!]
代码实现很简单,即用python爬虫不断请求文章页面即可.
主要用到requests库即可
别太过分了:-O
代码实现很简单,即用python爬虫不断请求文章页面即可.
主要用到requests库即可
别太过分了:-O
示例代码:
# -*- coding: utf-8 -*- # @Author : Sdite # @DateTime : 2017-07-16 14:17:22 import requests from bs4 import BeautifulSoup import re import time headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', } # 准备阶段,获取博客内文章的链接,存放在变量url中 url = "http://blog.csdn.net/vonsdite" res = requests.get(url=url, headers=headers) part = re.compile(r'<span class="link_title"><a href="(/vonsdite/article/details/.+?)"') url = part.findall(res.text) url = ['http://blog.csdn.net/' + tmp for tmp in url] # 刷阅读量阶段 while True: for u in url: res = requests.get(url=u, headers=headers) text = res.text soup = BeautifulSoup(text, 'lxml') rank = soup.select('#blog_rank') part = re.compile(r'<li>(访问:)<span>(\d+次)</span></li>') rank = part.findall(str(rank[0])) rank = rank[0][0] + rank[0][1] print('博客: ' + rank) time.sleep(2)
相关文章推荐
- Python爬虫简单实战,58同城西安二手笔电
- 实践项目十:爬取百度百科Python词条相关1000个页面数据(慕课简单爬虫实战)
- Python3 大型网络爬虫实战 002 --- scrapy 爬虫项目的创建及爬虫的创建 --- 实例:爬取百度标题和CSDN博客
- python开发简单爬虫:实战篇
- Python开发简单爬虫之实战演练
- Python爬虫实战(三):简单爬取网页图片
- 最简单的python爬虫实战——爬取王者荣耀皮肤及头像
- Python爬虫简单实战:抓取小猪短租西安市前五页民房数据
- Python爬虫实战入门二:从一个简单的HTTP请求开始
- python3.5简单爬虫爬取百度百科(参考imooc实战)
- python爬虫实战之最简单的网页爬虫教程
- Python爬虫实战入门三:简单的HTML解析——爬取腾讯新闻
- Python爬虫实战(十一):两种简单的方法爬取动态网页
- Python爬虫实战之爬取链家广州房价_01简单的单页爬虫
- Hello Python!用python写一个抓取CSDN博客文章的简单爬虫
- 转 Python爬虫实战二之爬取百度贴吧帖子
- python 简单爬虫实现
- python简单爬虫程序
- python 开发简单爬虫 by CL(一)
- 简单 python 爬虫(一)