随笔 - 172  文章 - 52  评论 - 6  阅读 - 17万

python3中的matplotlib绘图,绘制51job的python职位树形图

  python3中的matplotlib绘图,绘制51job上抓取的python各职位的树形图:

复制代码
import selenium  #测试框架
import selenium.webdriver  #模拟浏览器
import re
import matplotlib
import matplotlib.pyplot as plt   #数据可视化

matplotlib.rcParams["font.sans-serif"]=["simhei"] #配置字体 默认不支持中文
matplotlib.rcParams["font.family"]="sans-serif"

def getnumberbyname(searchname):
    url="https://search.51job.com/list/020000,000000,0000,00,9,99,"+searchname+",2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare="
    driver=selenium.webdriver.Chrome(executable_path="C:\Program Files (x86)\Google\Chrome\Application\chromedriver") #调用火狐浏览器
    driver.get(url)  #访问链接
    pagesource=driver.page_source   #抓取网页源代码
    #print(pagesource)  #打印源代码
    # 正则表达式
    # \s匹配任何不可见字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]
    #匹配任何可见字符。等价于[ ^ \f\n\r\t\v]      [] 匹配其中的任意一个
    restr="""<div class="rt">([\s\S]*?)</div>"""
    regex=re.compile(restr,re.IGNORECASE)
    mylist=regex.findall(pagesource)
    driver.close()  #关闭
    #print(mylist)
    if len(mylist)==0:
        print("失败")
    else:
        #print(mylist[0])
        newstr=mylist[0].strip()  #.strip()  去除前后空格空白符
        regex1=re.compile("(\d+)",re.IGNORECASE)
        mylist1 = regex1.findall(newstr)
        print(pystr+newstr)
        #print(mylist[0])


    return mylist1[0]
pythonlist=["python","python 运维","python 测试","python 数据","python web","python 爬虫"]
num=0
for pystr in pythonlist:
    num+=1
    eval(getnumberbyname(pystr))
    plt.bar([num],[eval(getnumberbyname(pystr))],label=pystr)

plt.legend()   #绘制
plt.savefig("zhaopin.png")    #保存图片到本地
#plt.show()    #显示
复制代码

 

posted on   共感的艺术  阅读(370)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示