实现:
跟踪比较活跃的微博号所发的微博内容,隔3-5分钟刷新(爬取)一次,只有更新了才爬的到,不爬取历史微博内容哦,爬取正文、文中图片、所属微博昵称、发布时间(时间戳格式)。
python_service.py
import win32serviceutil
import win32service
import win32event
import re,requests,time,datetime,pymysql,random
'''
遇到不懂的问题?Python学习交流群:821460695满足你的需求,资料都已经上传群文件,可以自行下载!
'''
WB_count1=8;WB_count=9;w1=0;Stop_py=1;w2=0
get_status=0
class SmallestPythonService(win32serviceutil.ServiceFramework):
_svc_name_ = "SmallestPythonService"
_svc_display_name_ = "The smallest possible Python Service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop process.
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
# And set my event.
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
global get_status
class crawl1:
def __init__(self):
pass
def getcontent(self,start_url1):
'''获取信息'''
global WB_count1,time_int,picture_name,cont_soure,cont,WB_count
html=requests.get(start_url1,cookies=cookie,headers=header,timeout=15)
html=html.content
reg=r't2\\">粉丝.*?ong clas.*?">(.*?)微博'
WB_count=re.findall(re.compile(reg),html) #发微博数量
if WB_count==[]:
self.GetBadCookie(I_D)
print 'cookie 被冻结'
cont,picture_name,cont_soure,time_int='1','1','1','1'
return cont,picture_name,cont_soure,time_int
else:
reg1=r' 来自
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?