# CIA文件爬取,正则,可视化处理 每日简报的策划,是为了加强对他国国情的认识,以及提升自己识别重要情报的能力。 以下是美国总统简报的公开检索途径, https://nsarchive2.gwu.edu/NSAEBB/NSAEBB116/index.htm https://www.cia.gov/readingroom/collection/presidents-daily-brief-1969-1977 from the Richard Nixon and Gerald Ford administrations. https://www.cia.gov/readingroom/collection/presidents-daily-brief-1961-1969 from the Kennedy and Johnson administrations. 情报简报是新闻简报的延申,下面我们将参照每日简报组织自己的活动,以立长期规划。每天本组的产出 可以分两步,第一步做公开信源的新闻摘要,同时开展对美国总统简报每日的学习。在这部分学习中不断加强对他国国情的认识,以及提升自己识别重要情报的能力。 在国别情报会之前,我们可能先要形成每日新闻简报,然后是同志们一起交流之后写成的每日情报简报,在这个过程中,如果能形成国别的专题讨论,那也算是国别情报组的雏形了。 # 关于学习材料的爬取,我们主要使用python ## 第一步是下载网页 ```markdown import requests import os for j in range(0,124): r = requests.get('https://www.cia.gov/readingroom/collection/presidents-daily-brief-1961-1969?page=' + str(j)) s = requests.session() #由于cia官网的落后,导致我们甚至需要用上的代码不带参数地运行一次来获取第一页。 with open("cia" + "/" + str(j) + ".html", "w", encoding='utf-8') as f: try: f.write(r.text) f.close() print( str(j) + "yes") except UnicodeEncodeError: print( str(j) + "fail") s.keep_alive = False ``` ## 第二步是从这些网页中提取到文件链接和其日期(从文件名中获取) ```markdown import requests import os path = './cia/' files = os.listdir(path) for file in range(13,124): FData = '' with open(f"{path}/{file}.html", "rb") as f: for line in f.readlines(): line = line.lower() FData += line.decode() #FData = FData.replace('\n', '').replace('\r', '') print({file}) #print(FData) #congress_pat = re.compile(r'

(.*?)

') #O = re.findall(congress_pat, FData) #经过多次尝试我发现这个div下的标签基本一样,除了文本正则基本没有办法摘出来。好在网页平均输出20个解密文件和相对固定的文件名,我们使用了两个列表p,q来对应储存。 #congress_pat2 = re.compile(r'the president's(.*?)') 你之后就会明白为什么不用这个。。。 congress_pat2 = re.compile(r'document/\d+(.*?)') p= re.findall(congress_pat2, FData) #p.insert(0,'null') print(len(p)) #print(str(p)) congress_pat3 = re.compile(r'png" /> Communication from Bachelor.