zoukankan      html  css  js  c++  java
  • 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)GoogleChromeApplicationchromedriver") #调用火狐浏览器
        driver.get(url)  #访问链接
        pagesource=driver.page_source   #抓取网页源代码
        #print(pagesource)  #打印源代码
        # 正则表达式
        # s匹配任何不可见字符,包括空格、制表符、换页符等等。等价于[ f
    
    	v]
        #匹配任何可见字符。等价于[ ^ f
    
    	v]      [] 匹配其中的任意一个
        restr="""<div class="rt">([sS]*?)</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()    #显示
  • 相关阅读:
    莫队模板
    CF600E Lomsat gelral
    JZOJ 捕老鼠
    JZOJ 4896. 【NOIP2016提高A组集训第16场11.15】兔子
    JZOJ 4895【NOIP2016提高A组集训第16场11.15】三部曲
    双端队列xLIS问题
    最大K段和
    你真的了解ES6的promise吗?
    JS对象和数组深浅拷贝总结②
    当前页码删除唯一数据后加载前一页内容
  • 原文地址:https://www.cnblogs.com/my-global/p/12447277.html
Copyright © 2011-2022 走看看