实现:
跟踪比较活跃的微博号所发的微博内容,隔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' 来自
关注
打赏
热门博文
- Python骚操作,实现驾考自动答题,这就直接满分了?
- 用Python自动实现图表可视化操作,提高工作效率,又能有更多的时间摸鱼了~
- Python:用tkinter制做一个音乐下载小软件
- Python丨小学妹喜欢看漫画,于是我写了四十行代码获取了它所有漫画
- 女同桌找我要表情包,还好我会Python,分分钟给她下载几十个G...
- 为了防止这上面的文章被封,我连夜用Python获取了它所有内容,真香~
- 这个Python读取文件的方法,堪称天花板级别...
- Python做一个通过输入bv号就能下载视频的工具,评论和弹幕也不放过
- Python爬虫何如抓包?这三个案例手把手教会你,非常详细...
- Python:50行代码实现下载小说,图片章节可自动识别转文字保存...