马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
from lxml import etree
from pyecharts import options
from pyecharts.charts import Bar
from pypinyin import lazy_pinyin
def get(url):
response = requests.get(url).content.decode('gbk')
#print(response)
html = etree.HTML(response)
year=html.xpath('//th[@width="72"]/text()')[0:11]
wenke=html.xpath('//tr[@class="c_blue"]/td/text()')[0:12]+html.xpath('//tr[@class="c_white"]/td/text()')[0:12]
wen = []
for i in wenke:
i = i.replace('\r','').replace('\n','').replace('\t','')
wen.append(i)
like = html.xpath('//div[@class="cjArea tm15"]/table[last()]/tr[@class="c_blue"]/td/text()')[0:12]+html.xpath('//div[@class="cjArea tm15"]/table[last()]/tr[@class="c_white"]/td/text()')[0:12]
li = []
for i in like:
i = i.replace('\r', '').replace('\n', '').replace('\t', '')
li.append(i)
visulize(pro,li,wen,year)
pass
def visulize(pro,li,wen,year):
wen1 = wen[1:12]
wen2 = wen[13:24]
li1 = li[1:12]
li2 = li[13:24]
c = Bar() #生成条形图
#添加x,y
c.add_xaxis(year)
c.add_yaxis('文科一本',wen1)
c.add_yaxis('文科二本', wen2)
c.add_yaxis('理科一本', li1)
c.add_yaxis('理科二本', li2)
c.set_global_opts(title_opts=options.TitleOpts(title=pro+"历年高考分数线",subtitle="2009-2019年"))
c.render(pro+"历年高考分数线.html")
pass
if __name__ == '__main__':
pro = input('想要获得的省份:')
prov = lazy_pinyin(pro)
prov = "".join(prov)
url = 'http://www.gaokao.com/'+prov+'/fsx/'
get(url)
|