| import time | |
| import csv | |
| import os | |
| import re | |
| from bs4 import BeautifulSoup | |
| def FindKey(RecordText, KeyWords): | |
| if any(word in RecordText for word in KeyWords): | |
| output = 1 | |
| else: | |
| output = 0 | |
| return output | |
| KeyWords1 = ['气','烟','尘','二氧化硫','颗粒','脱硝','脱硫','炉','焚烧','NO','PM'] | |
| KeyWords2 = ['污水','水污染','沉淀','沟','渠','COD'] | |
| KeyWords3 = ['固体'] | |
| KeyWords4 = ['未批先建','批建不符','未验先投','清理明细表','开工','环评','手续','三同时','未经验收'] | |
| KeyWords5 = ['罚款','经济处罚','万元'] | |
| KeyWords6 = ['停'] | |
| KeyWords7 = ['改','维修'] | |
| htfile = "output.txt" | |
| fo = open(htfile, "w", encoding='utf_8_sig') | |
| with open('records.csv', 'r') as f: | |
| reader = csv.reader(f) | |
| records_list = list(reader) | |
| for record in records_list: | |
| dir_path = '/Volumes/forMac/list/'+str(record[0]) | |
| address = dir_path+'/'+str(record[1]) | |
| print(address) | |
| fo.write(str(record[1])) | |
| soup = BeautifulSoup(open(address).read(), "html.parser") | |
| output1=0 | |
| output2=0 | |
| output3=0 | |
| output4=0 | |
| output5=0 | |
| output6=0 | |
| output7=0 | |
| tables = soup.find_all('table') | |
| cells = soup.find_all(style="color:#eeeeee;background-color:#3399FF") | |
| if len(cells)==0: | |
| output1=0 | |
| output2=0 | |
| output3=0 | |
| else: | |
| if len(tables)==0: | |
| text = soup.get_text() | |
| else: | |
| try: | |
| block = cells[-1].find_parents('tr')[-1] | |
| row = block.find_all('td') | |
| if len(row)<4: | |
| text = soup.get_text() | |
| else: | |
| text = block.get_text() | |
| except: | |
| text = soup.get_text() | |
| output1 = FindKey(text, KeyWords1) | |
| output2 = FindKey(text, KeyWords2) | |
| output3 = FindKey(text, KeyWords3) | |
| output4 = FindKey(text, KeyWords4) | |
| output5 = FindKey(text, KeyWords5) | |
| output6 = FindKey(text, KeyWords6) | |
| output7 = FindKey(text, KeyWords7) | |
| total=output1+output2+output3+output4 | |
| if total==0: | |
| text = soup.get_text() | |
| output4 = FindKey(text, KeyWords4) | |
| fo.write(",") | |
| fo.write(str(output1)) | |
| fo.write(",") | |
| fo.write(str(output2)) | |
| fo.write(",") | |
| fo.write(str(output3)) | |
| fo.write(",") | |
| fo.write(str(output4)) | |
| fo.write(",") | |
| fo.write(str(output5)) | |
| fo.write(",") | |
| fo.write(str(output6)) | |
| fo.write(",") | |
| fo.write(str(output7)) | |
| fo.write("\n") | |
| fo.close() | |