from tkinter import *
import requests
from openpyxl import load_workbook
from concurrent.futures import ThreadPoolExecutor
def g():
# elif btn1['state'] == 'disabled':
# btn1['state'] = 'normal'
# btn1['text'] = "ni"
# if but['state'] == 'normal':
h = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36'
}
addr = 'C:/Users/Dell/Desktop/电视链接.xlsx'
wb = load_workbook(addr)
sheet = wb["数据源"]
sheet2 = wb["异常"]
sheet3 = wb["正常"]
global 数量
row_max = sheet.max_row
数量=row_max
print(数量)
链接集合 = []
异常链接 = []
正常链接 = []
for i in range(1, row_max, 1):
if sheet.cell(i, 1)._hyperlink is None:
print("没有超链接 ")
# print("cc", sheet.cell(i, 1)) #<Cell '数据源'.A1>
#['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_bind_value', '_comment', '_hyperlink', '_style', '_value', 'alignment', 'base_date', 'border', 'check_error', 'check_string', 'col_idx', 'column', 'column_letter', 'comment', 'coordinate', 'data_type', 'encoding', 'fill', 'font', 'has_style', 'hyperlink', 'internal_value', 'is_date', 'number_format', 'offset', 'parent', 'pivotButton', 'protection', 'quotePrefix', 'row', 'style', 'style_id', 'value']
else:
# print("cc", dir(sheet.cell(i, 1).hyperlink))
# print("aa",sheet.cell(i, 1).hyperlink) # <openpyxl.worksheet.hyperlink.Hyperlink object>
# #Parameters:ref='A2', location=None, tooltip='https://pan.baidu.com/s/113ADCqIc5mzOruVBEICn6A', display='初恋那么多年', id='rId1'
# print("bb",type(sheet.cell(i, 1).hyperlink))
# <class 'openpyxl.worksheet.hyperlink.Hyperlink'>
# if isinstance(sheet.cell(i, 1).value,int):
# print("duide")
# if not hasattr(sheet.cell(i, 1),"hyperlink"):
# print("meiyou")
# else:
剧名 = sheet.cell(i, 1).value
链接 = sheet.cell(i, 1).hyperlink.target
链接集合.append([剧名, 链接])
def 检查异常(url):
da = requests.get(url[1], headers=h, )
html = da.content
html_doc = str(html, 'utf-8')
if html_doc.find('class="error-img"') != -1:
异常链接.append([url[0], url[1]])
else:
正常链接.append([url[0], url[1]])
pool = ThreadPoolExecutor(20)
for url in 链接集合:
v = pool.submit(检查异常, url)
a = 1
b = 1
pool.shutdown(wait=True)
for c in 异常链接:
sheet2.cell(row=a, column=1, value=c[0])
sheet2.cell(row=a, column=2, value=c[1])
a += 1
for d in 正常链接:
sheet3.cell(row=b, column=1, value=d[0])
sheet3.cell(row=b, column=2, value=d[1])
b += 1
wb.save(addr)
# str.set("操作结束")
root=Tk()
root.title("查看异常链接")
# str=StringVar()
but=Button(root,text='点击开始',font=('KaiTi',36,'bold'),state='normal',bg='pink',fg='green',bd=2,width=10,command=g)
# listb = Label(root, textvariable=str, fg='red', font=('宋体', 10))
# str.set("点击开始操作")
# listb.pack()
but.pack()
root.mainloop()
from tkinter import *
import requests
from openpyxl import load_workbook
from concurrent.futures import ThreadPoolExecutor
def g():
# elif btn1['state'] == 'disabled':
# btn1['state'] = 'normal'
# btn1['text'] = "ni"
# if but['state'] == 'normal':
but['text'] = '正在进行'
h = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36'
}
addr = 'C:/Users/Dell/Desktop/电视链接.xlsx'
wb = load_workbook(addr)
sheet = wb["数据源"]
sheet2 = wb["异常"]
sheet3 = wb["正常"]
global 数量
row_max = sheet.max_row
数量=row_max
print(数量)
链接集合 = []
异常链接 = []
正常链接 = []
for i in range(1, row_max, 1):
剧名 = sheet.cell(i, 1).value
链接 = sheet.cell(i, 1).hyperlink.target
链接集合.append([剧名, 链接])
def 检查异常(url):
da = requests.get(url[1], headers=h, )
html = da.content
html_doc = str(html, 'utf-8')
if html_doc.find('class="error-img"') != -1:
异常链接.append([url[0], url[1]])
else:
正常链接.append([url[0], url[1]])
pool = ThreadPoolExecutor(20)
for url in 链接集合:
v = pool.submit(检查异常, url)
a = 1
b = 1
pool.shutdown(wait=True)
for c in 异常链接:
sheet2.cell(row=a, column=1, value=c[0])
sheet2.cell(row=a, column=2, value=c[1])
a += 1
for d in 正常链接:
sheet3.cell(row=b, column=1, value=d[0])
sheet3.cell(row=b, column=2, value=d[1])
b += 1
wb.save(addr)
# str.set("操作结束")
root=Tk()
root.title("查看异常链接")
# str=StringVar()
but=Button(root,text='点击开始',font=('KaiTi',36,'bold'),state='normal',bg='pink',fg='green',bd=2,width=10,command=g)
# listb = Label(root, textvariable=str, fg='red', font=('宋体', 10))
# str.set("点击开始操作")
# listb.pack()
but.pack()
root.mainloop()