Newbie_XZW 发表于 2020-12-24 10:49:45

【CPA薪资对比器】小白同志学了一个多月python,也来献献丑

首先,用selenium模块 爬取 前程无忧 前10页 关于CPA的薪资

代码:

from selenium import webdriver
import time
wb = webdriver.Chrome()
wb.get('https://search.51job.com/list/000000,000000,0000,00,9,99,%25E6%25B3%25A8%25E5%2586%258C%25E4%25BC%259A%25E8%25AE%25A1%25E5%25B8%2588,2,1.html?lang=c&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare=')
wb.implicitly_wait(5)

money_list = []
company_list = []
page = 10
while page:
    money = wb.find_elements_by_css_selector('.j_joblist .sal') # css表达式可以好好研究一下
    company = wb.find_elements_by_css_selector('.j_joblist .er > ')
    element = wb.find_element_by_css_selector('.p_in .next ')
    for each in money:
      money_list.append(each.text)

    for each in company:
      company_list.append(each.text)

    element.click()
    time.sleep(2)
    page -= 1

a = list(zip(company_list, money_list))

with open('CPA薪资情况.txt','a') as f:
    for c, m in a:
      f.writelines(c + ' -> ' + m + '\n')


wb.quit()




然后,用刚学的Tkinter模块做了个图形界面窗口

代码:

from tkinter import *

master = Tk()

frame1 = Frame(master)
frame2 = Frame(master)

s = Scrollbar(frame1)
s.pack(side=RIGHT,fill=Y)

lb = Listbox(frame1,yscrollcommand=s.set,width=50,selectmode=EXTENDED)
lb.pack(fill=BOTH,side=LEFT)

with open('/Users/nishokubun/Desktop/鱼C/爬虫/CPA薪资情况.txt') as f:
    for i in f:
      lb.insert(END, i)

s.config(command=lb.yview)


def choice():
    tup = lb.curselection()
    list1 = lb.get(tup,tup[-1])
    for each in list1:
      print(each)


Button(frame2,text='选择',command=choice).pack()

frame1.pack()
frame2.pack()
mainloop()



最后:

感谢小甲鱼{:10_256:}


页: [1]
查看完整版本: 【CPA薪资对比器】小白同志学了一个多月python,也来献献丑