PyQt 第二弹 - 快速找工作程序
前两天,我用QT写了个基于有道的词典,由于才刚接触QT,所以写得很烂,在改进的同时,我又开始了另外一个实验,本次实验为:通过爬虫抓取招聘信息,并通过UI呈现出来,爬取深度为:一个页面,目前已实现大部分功能,剩下超链接部分未完工,大家有兴趣的可以自行研发!
爬虫部分源代码如下:
__author__ = 'NarutoLee'
#coding: utf-8
import requests,time,urllib
from bs4 import BeautifulSoup
def request(job,aeca,flog):
title = urllib.parse.quote('工作')
q = urllib.parse.quote(job)
l = urllib.parse.quote(aeca)
url = 'http://cn.indeed.com/%s?q=%s&l=%s' % (title, q, l)
url2 = 'http://cn.indeed.com/%s?q=%s&l=%s&%s' % (title,q,l,'sort=date')
headers = {
'Accept': '*/*',
'Connection':'keep-alive',
'Host':'cn.indeed.com',
'Origin':'http://cn.indeed.com',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
}
data = {
'q':q,
'l':l,
}
session = requests.session()
if flog == 'No':
get_job = session.get(url2,data=data,headers=headers)
elif flog == 'OFF':
get_job = session.get(url, data=data, headers=headers)
soup = BeautifulSoup(get_job.text,'lxml')
gangwei = []
gongsi = []
dizi = []
xinxi = []
fabu = []
laiyuan = []
laiyuan2 =[]
for i in soup.select('.row'):
if i.select('.jobtitle') != []:
#print('招聘岗位:'+ i.select('.jobtitle').text.strip('\n'))
gangwei.append(i.select('.jobtitle').text.strip('\n'))
if i.select('.company') != []:
#print('公司名称:'+ i.select('.company').text.strip())
gongsi.append(i.select('.company').text.strip())
if i.select('.location') != []:
# print('地址:'+ i.select('.location').text.strip('\n'))
dizi.append(i.select('.location').text.strip('\n'))
# print(i.select('.summary').text.strip('\n'))
xinxi.append(i.select('.summary').text.strip('\n'))
if i.select('.date') != []:
#print('发布日期:'+ i.select('.date').text.strip('\n'))
fabu.append(i.select('.date').text.strip('\n'))
if i.select('.sdn') != []:
#print('信息来源:'+ i.select('.sdn').text.strip('\n'))
laiyuan.append(i.select('.sdn').text.strip('\n'))
if i.select('.result-link-source') != []:
# print('信息来自:'+ i.select('.result-link-source').text.strip('\n'))
laiyuan2.append(i.select('.result-link-source').text.strip('\n'))
return gangwei,gongsi,dizi,xinxi,fabu,laiyuan,laiyuan2
#request('Java','广州')
GUI部分代码:
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
from sackpys import *
import sys
from PyQt5.QtWidgets import QApplication,QMainWindow,QTableWidgetItem,QHeaderView
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1110, 856)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 0, 860, 41))
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(12)
self.label.setFont(font)
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(210, 40, 211, 41))
self.lineEdit.setObjectName("lineEdit")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 50, 201, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(430, 50, 121, 16))
self.label_3.setObjectName("label_3")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(550, 40, 211, 41))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(770, 50, 71, 16))
self.label_4.setObjectName("label_4")
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox.setGeometry(QtCore.QRect(850, 40, 151, 19))
self.checkBox.setObjectName("checkBox")
self.checkBox_2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_2.setGeometry(QtCore.QRect(850, 60, 151, 19))
self.checkBox_2.setObjectName("checkBox_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(1000, 40, 93, 41))
self.pushButton.setObjectName("pushButton")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(5, 101, 1101, 731))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(6)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(5, item)
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(540, 790, 71, 21))
self.label_5.setObjectName("label_5")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1110, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "EasyJob - 您身边的求职专家"))
self.label.setText(_translate("MainWindow", "欢迎使用EasyJob快速找工作程序,使用高级搜寻功能请勾上其中一个复选框,否则将默认按日期排序,最后祝您好运!"))
self.label_2.setText(_translate("MainWindow", "请输入要查询的职位关键字:"))
self.label_3.setText(_translate("MainWindow", "请输入工作区域:"))
self.label_4.setText(_translate("MainWindow", "高级搜寻:"))
self.checkBox.setText(_translate("MainWindow", "根据相关信息搜寻"))
self.checkBox_2.setText(_translate("MainWindow", "根据最新日期搜寻"))
self.pushButton.setText(_translate("MainWindow", "搜寻"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "招聘岗位"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "公司名称"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "所在地"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "招聘需求"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "发布日期"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("MainWindow", "信息来源"))
self.label_5.setText(_translate("MainWindow", "By:NarutoLee"))
self.pushButton.clicked.connect(self.result)
def result(self):
for i in reversed(range(self.tableWidget.rowCount())):
self.tableWidget.removeRow(i)
self.job = self.lineEdit.text()
self.acea = self.lineEdit_2.text()
if self.checkBox_2.isChecked():
self.result = 'No'
else:
self.result = 'OFF'
self.get_reques = request(self.job, self.acea,self.result)
gangwei, gongsi, dizi, xinxi, fabu, laiyuan, laiyuan2 = self.get_reques
laiyuan_lis = laiyuan + laiyuan2
# self.tableWidget.setRowCount(len(gangwei))
tem = len(gangwei)
for (ls1,ls2,ls3,ls4,ls5,ls6) in zip(gangwei,gongsi,dizi,xinxi,fabu,laiyuan_lis):
self.tableWidget.insertRow(0)
self.tableWidget.setItem(0, 0, QTableWidgetItem(ls1))
self.tableWidget.setItem(0, 1, QTableWidgetItem(ls2))
self.tableWidget.setItem(0, 2, QTableWidgetItem(ls3))
self.tableWidget.setItem(0, 3, QTableWidgetItem(ls4))
self.tableWidget.setItem(0, 4, QTableWidgetItem(ls5))
self.tableWidget.setItem(0, 5, QTableWidgetItem(ls6))
tem -=1
MainWindow.setStatusTip('信息加载完毕!')
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
页:
[1]