功能
输入博主用户名,增加博主点击量
软件截图
部分源码
# coding=utf-8 __author__ = 'a359680405' from PyQt5 import QtWidgets from PyQt5.QtCore import QThread from PyQt5.QtCore import pyqtSignal from visitspage.UI.MainForm import Ui_MainForm from visitspage.UI.newForm import Ui_newForm import re,time import urllib.request from bs4 import BeautifulSoup class WorkThread(QThread): _strName="a359680405" _brushNum=50 trigger=pyqtSignal(str) #传参 def __init__(self,strName,brushNum): super(WorkThread,self).__init__() self._strName=strName self._brushNum=brushNum def run(self): p=re.compile('/'+self._strName+'/article/details/........') #自己的博客主页 url = "http://blog.csdn.net/"+self._strName #使用build_opener()是为了让python程序模仿浏览器进行访问 opener = urllib.request.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] try: html = opener.open(url).read().decode('utf-8') except urllib.error.HTTPError: #print('urllib.error.HTTPError') self.trigger.emit('无此用户 ') time.sleep(1)#出现错误,停几秒先 allfinds = p.findall(html) #print(allfinds) self.trigger.emit(str(allfinds)) urlBase = "http://blog.csdn.net"#需要将网址合并的部分 #页面中的网址有重复的,需要使用set进行去重复 mypages = list(set(allfinds)) for i in range(len(mypages)): mypages[i] = urlBase+mypages[i] #print('要刷的网页有:') self.trigger.emit('要刷的网页有:') for index , page in enumerate(mypages) : # print(str(index), page) self.trigger.emit(str(index)+ page) #所有的页面都刷 #print('下面开始刷了哦:') self.trigger.emit('下面开始刷了哦:') for index , page in enumerate(mypages) : for j in range(self._brushNum): try : pageContent = opener.open(page).read().decode('utf-8') #使用BeautifulSoup解析每篇博客的标题 soup = BeautifulSoup(pageContent) blogTitle = str(soup.title.string) blogTitle = blogTitle[0:blogTitle.find('-')] #print(str(j) , blogTitle) self.trigger.emit(str(j)+" "+ blogTitle) except urllib.error.HTTPError as e: #print('urllib.error.HTTPError') self.trigger.emit('urllib.error.HTTPError ') time.sleep(1)#出现错误,停几秒先 except urllib.error.URLError: #print('urllib.error.URLError') self.trigger.emit('urllib.error.URLError') time.sleep(1)#出现错误,停几秒先 time.sleep(0.1)#正常停顿,以免服务器拒绝访问 class VpForm(QtWidgets.QMainWindow,Ui_MainForm): def __init__(self): super(VpForm,self).__init__() self.setupUi(self) self._worker=[] self._form=[] self.submitBt.clicked.connect(self.shua) #索引增加 def shua(self): thread=WorkThread(self.nameLe.text(),int(self.numLe.text())) form=NewForm() thread.trigger.connect(form.display) form.show() thread.start() self._worker.append(thread) self._form.append(form) class NewForm(QtWidgets.QWidget,Ui_newForm): def __init__(self): super(NewForm,self).__init__() self.setupUi(self) def display(self,m): self.displayTb.append(m) if __name__=="__main__": import sys app=QtWidgets.QApplication(sys.argv) myshow=VpForm() myshow.show() sys.exit(app.exec_())
完整源码地址http://download.csdn.net/detail/a359680405/9046865 (资源已经被删 - -)