from tkinter import *
import requests
from lxml import etree
from tkinter import ttk
from bs4 import BeautifulSoup
import webbrowser
from tkinter import messagebox
from openpyxl import Workbook
import time
treedata1=[]
def download_song():
datas = {"page.pageNo": "1",
"page.orderBy": "",
"page.order": "",
"province": "210000000000",
"city": "211300000000",
"registerentername": "",
"xkznum": "",
"treadname": "",
"treadcode": "",
"publishtime": ""}
url = "http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action"
r = requests.post("http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action", data=datas)
r = requests.post(url, data=datas)
html = etree.HTML(r.text)
urlpage = html.xpath('//div[@class="fr margin-t-33 margin-b-20"]/a/@onclick')[5]
urlpageidstr = urlpage[21:23]
start_page = 1
urlpageidstr = 2
messagebox.showinfo("提示", "数据正在读取请稍候。。。。")
for page in range(start_page, urlpageidstr):
content = page
urlpage = content
datas = {"page.pageNo": urlpage,
"page.orderBy": "",
"page.order": "",
"province": "210000000000",
"city": "211300000000",
"registerentername": "",
"xkznum": "",
"treadname": "",
"treadcode": "",
"publishtime": ""}
url = "http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action"
r = requests.post("http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action", data=datas)
r = requests.post(url, data=datas)
html = etree.HTML(r.text)
href_url = html.xpath('//table[@class="tabtd"]/tr/td/a/@href')
href_name = html.xpath('//table[@class="tabtd"]/tr')[1:]
urlpage = html.xpath('//div[@class="fr margin-t-33 margin-b-20"]/a/@onclick')[5]
i = 0
datasum=0
for href_url, roos in zip(href_url, href_name):
addurl = href_url
name = roos.xpath('./td[4]/text()')[0]
i = i + 1
addurl = addurl[39:93]
datas = {"xkgk": "getxxgkContent",
"dataid": addurl}
url = "http://permit.mee.gov.cn/permitExt/xkgkAction!xkgk.action?xkgk=" + addurl
html = requests.get(url, headers=datas)
soup = BeautifulSoup(html.text, 'lxml')
name_id = soup.find_all('p', style="font-size:36px;")[0].text
name_add = soup.find_all('p', style="font-weight: bold;color: green;font-size: 14px;")[0].text
content = name_add
content = content.strip()
content = content.split()
str2 = ''.join(content)
u1, u2, u3, u4, u5 = str2.split(':', 4)
f1 = u2.find('行业类别')
f2 = u2[0:f1]
g1 = u3.find('所在地区')
g2 = u3[0:g1]
h1 = u4.find('发证机关')
h2 = u4[0:h1]
paiwuxukebianhao=soup.find_all('table', class_="tab0")[0].text.strip().replace('\n', '').replace('\r', '').replace(' ', '')
paiwuxkzid=paiwuxukebianhao[19:42]
paiwuxukedata=paiwuxukebianhao[45:56]
paiwuxukeyouxiaoqi=paiwuxukebianhao[69:79]
addurl=addurl[22:]
url_idshui = addurl + '&isVersion=&operate=readonly'
urlshui = "http://permit.mee.gov.cn/permitExt/xkgkAction!xkgk.action?xkgk=approveWater_xkzgk&dataid=" + url_idshui
html = requests.get(urlshui).text
html = etree.HTML(html)
shuicod = html.xpath('//table[@id="fswrwinfo4"]/tr[3]/td[1]/text()')
shuiandan = html.xpath('//table[@id="fswrwinfo4"]/tr[4]/td[1]/text()')
shuicod = "".join(shuicod).replace('\n', '').replace('\r', '').replace('\t', '')
shuiandan = "".join(shuiandan).replace('\n', '').replace('\r', '').replace('\t', '')
urldaqi = "http://permit.mee.gov.cn/permitExt/xkgkAction!xkgk.action?xkgk=approveAtmosphere_xkzgk&dataid=" + url_idshui
html = requests.get(urldaqi).text
html = etree.HTML(html)
shuiso2 = html.xpath('//table[@id="spenterair"]/tr[4]/td[1]/text()')
shuidanyanghuawu = html.xpath('//table[@id="spenterair"]/tr[5]/td[1]/text()')
shuiso2 = "".join(shuiso2).replace('\n', '').replace('\r', '').replace('\t', '')
shuidanyanghuawu = "".join(shuidanyanghuawu).replace('\n', '').replace('\r', '').replace('\t', '')
treedata1.append([i,name,f2,g2,h2,u5,paiwuxkzid,paiwuxukedata,paiwuxukeyouxiaoqi,shuicod,shuiandan,shuiso2,shuidanyanghuawu])
tree.insert("",i,text="",values=(i,name,f2,g2,h2,u5,paiwuxkzid,paiwuxukedata,paiwuxukeyouxiaoqi,shuicod,shuiandan,shuiso2,shuidanyanghuawu))
tree.update()
print("不要急正在爬取内容...一共"+str(urlpageidstr)+"现在第"+str(i)+"页")
datasum = datasum + 1
messagebox.showinfo("提示", "数据查询完毕,共 "+str(datasum)+" 条记录。")
def treesave():
print(treedata1)
wb = Workbook()
ws = wb.active
aa=len(tree.get_children())
tableTitle = ['序号','企业名称','生产经营场所地址','行业类别','所在地区','发证机关','许可证编号','办结日期','有效期限','COD年排放量','氨氮年排放量','二氧化硫年排放量','氮氧化物年排放量']
for col in range(len(tableTitle)):
c = col + 1
ws.cell(row=1, column=c).value = tableTitle[col]
for row in range(len(treedata1)):
ws.append(treedata1[row])
wb.save("d:\\1.xlsx")
root = Tk()
root.title("label-test")
root.geometry("1024x768+100+200")
l = Label(root, text="请输入要下载的歌单URL", font=("Arial", 12), width=20, height=5)
l.grid()
enter1 = Entry(root)
enter1.grid(row=0, column=1)
tree = ttk.Treeview(root, show="headings")
tree.grid(row=1, columnspan=2)
tree["columns"] = ('序号','企业名称','生产经营场所地址','行业类别','所在地区','发证机关','许可证编号','办结日期','有效期限','COD年排放量','氨氮年排放量','二氧化硫年排放量','氮氧化物年排放量')
tree.column("序号", width=100)
tree.column("企业名称", width=100)
tree.column("生产经营场所地址", width=100)
tree.column("行业类别", width=100)
tree.column("所在地区", width=100)
tree.column("发证机关", width=100)
tree.column("许可证编号", width=100)
tree.column("办结日期", width=100)
tree.column("有效期限", width=100)
tree.column("COD年排放量", width=100)
tree.column("氨氮年排放量", width=100)
tree.column("二氧化硫年排放量", width=100)
tree.column("氮氧化物年排放量", width=100)
tree.heading("序号", text="序号")
tree.heading("企业名称", text="企业名称")
tree.heading("生产经营场所地址", text="生产经营场所地址")
tree.heading("行业类别", text="行业类别")
tree.heading("所在地区", text="所在地区")
tree.heading("发证机关", text="发证机关")
tree.heading("许可证编号", text="许可证编号")
tree.heading("办结日期", text="办结日期")
tree.heading("有效期限", text="有效期限")
tree.heading("COD年排放量", text="COD年排放量")
tree.heading("氨氮年排放量", text="氨氮年排放量")
tree.heading("二氧化硫年排放量", text="二氧化硫年排放量")
tree.heading("氮氧化物年排放量", text="氮氧化物年排放量")
"""
定义滚动条控件
orient为滚动条的方向,vertical--纵向,horizontal--横向
command=self.tree.yview 将滚动条绑定到treeview控件的Y轴
"""
scroll_ty = Scrollbar(root, orient=VERTICAL, command=tree.yview)
scroll_ty.grid(row=1, column=2, sticky=N+S)
tree['yscrollcommand']=scroll_ty.set
scroll_tx = Scrollbar(root, orient=HORIZONTAL, command=tree.xview)
scroll_tx.grid(row=2, column=0, sticky=E+W)
tree['xscrollcommand']=scroll_tx.set
def tree_click(event):
item_text = tree.item(tree.selection(), 'values')[1]
messagebox.showinfo("提示", "你所选择的数据是:"+item_text)
tree.bind('', tree_click)
button = Button(root, text="开始下载", font=('华文行楷', 10), command=download_song)
button.grid(row=5, column=0, sticky=W)
button1 = Button(root, text="退出", font=('华文行楷', 10), command=root.quit)
button1.grid(row=5, column=1, sticky=W)
button2 = Button(root, text="treesave", command=treesave)
button2.grid(row=6, column=0, sticky=W)
root.mainloop()
from tkinter import *
import requests
from lxml import etree
import tkinter
from tkinter import ttk
from bs4 import BeautifulSoup
import webbrowser
from tkinter import messagebox
import ast
from openpyxl import Workbook
treedata1=[]
def download_song():
datas = {"page.pageNo": "1",
"page.orderBy": "",
"page.order": "",
"province": "210000000000",
"city": "211300000000",
"registerentername": "",
"xkznum": "",
"treadname": "",
"treadcode": "",
"publishtime": ""}
url = "http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action"
r = requests.post("http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action", data=datas)
r = requests.post(url, data=datas)
html = etree.HTML(r.text)
urlpage = html.xpath('//div[@class="fr margin-t-33 margin-b-20"]/a/@onclick')[5]
urlpageidstr = urlpage[21:23]
start_page = 1
urlpageidstr=(int(urlpageidstr))
messagebox.showinfo("提示", "数据正在读取请稍候。。。。")
for page in range(start_page, urlpageidstr):
content = page
urlpage = content
datas = {"page.pageNo": urlpage,
"page.orderBy": "",
"page.order": "",
"province": "210000000000",
"city": "211300000000",
"registerentername": "",
"xkznum": "",
"treadname": "",
"treadcode": "",
"publishtime": ""}
url = "http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action"
r = requests.post("http://permit.mee.gov.cn/permitExt/syssb/xkgg/xkgg!licenseInformation.action", data=datas)
r = requests.post(url, data=datas)
html = etree.HTML(r.text)
href_url = html.xpath('//table[@class="tabtd"]/tr/td/a/@href')
href_name = html.xpath('//table[@class="tabtd"]/tr')[1:]
urlpage = html.xpath('//div[@class="fr margin-t-33 margin-b-20"]/a/@onclick')[5]
urlpageidstr = urlpage[21:23]
i = 0
for href_url, roos in zip(href_url, href_name):
addurl = href_url
name = roos.xpath('./td[4]/text()')[0]
i = i + 1
addurl = addurl[39:93]
datas = {"xkgk": "getxxgkContent",
"dataid": addurl}
url = "http://permit.mee.gov.cn/permitExt/xkgkAction!xkgk.action?xkgk=" + addurl
html = requests.get(url, headers=datas)
soup = BeautifulSoup(html.text, 'lxml')
name_id = soup.find_all('p', style="font-size:36px;")[0].text
name_add = soup.find_all('p', style="font-weight: bold;color: green;font-size: 14px;")[0].text
content = name_add
content = content.strip()
content = content.split()
str2 = ''.join(content)
u1, u2, u3, u4, u5 = str2.split(':', 4)
f1 = u2.find('行业类别')
f2 = u2[0:f1]
g1 = u3.find('所在地区')
g2 = u3[0:g1]
h1 = u4.find('发证机关')
h2 = u4[0:h1]
ii = str(i)
treedata1.append([i,name,f2,g2,h2,u5])
tree.insert("",i,text="",values=(i,name,f2,g2,h2,u5))
print("不要急正在爬取内容...一共"+str(urlpageidstr)+"现在第"+str(i)+"页")
def treesave():
print(treedata1)
wb = Workbook()
ws = wb.active
aa=len(tree.get_children())
tableTitle = ["序号", "企业名称", "生产经营场所地址", "行业类别", "所在地区", "发证机关"]
for col in range(len(tableTitle)):
c = col + 1
ws.cell(row=1, column=c).value = tableTitle[col]
for row in range(len(treedata1)):
ws.append(treedata1[row])
wb.save("d:\\1.xlsx")
root = Tk()
root.title("label-test")
root.geometry("800x900+300+100")
l = Label(root, text="请输入要下载的歌单URL", font=("Arial", 12), width=20, height=5)
l.grid()
enter1 = Entry(root)
enter1.grid(row=0, column=1)
tree = ttk.Treeview(root, show="headings")
tree.grid(row=1, columnspan=2)
tree["columns"] = ("序号", "企业名称", "生产经营场所地址", "行业类别", "所在地区", "发证机关")
tree.column("序号", width=100)
tree.column("企业名称", width=100)
tree.column("生产经营场所地址", width=100)
tree.column("行业类别", width=100)
tree.column("所在地区", width=100)
tree.column("发证机关", width=100)
tree.heading("序号", text="序号")
tree.heading("企业名称", text="企业名称")
tree.heading("生产经营场所地址", text="生产经营场所地址")
tree.heading("行业类别", text="行业类别")
tree.heading("所在地区", text="所在地区")
tree.heading("发证机关", text="发证机关")
def tree_click(event):
item_text = tree.item(tree.selection(), 'values')[1]
messagebox.showinfo("提示", "你所选择的数据是:"+item_text)
tree.bind('', tree_click)
button = Button(root, text="开始下载", font=('华文行楷', 10), command=download_song)
button.grid(row=5, column=0, sticky=W)
button1 = Button(root, text="退出", font=('华文行楷', 10), command=root.quit)
button1.grid(row=5, column=1, sticky=W)
button2 = Button(root, text="treesave", command=treesave)
button2.grid(row=6, column=0, sticky=W)
root.mainloop()