File size: 2,535 Bytes
3fb2143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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()