Create adapters/cia.py
Browse files- adapters/cia.py +21 -0
adapters/cia.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .common import fetch, clean
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
|
| 4 |
+
def search_cia(query):
|
| 5 |
+
url = "https://www.cia.gov/readingroom/search/site/"
|
| 6 |
+
html = fetch(url, {"search_api_fulltext": query})
|
| 7 |
+
soup = BeautifulSoup(html, "html.parser")
|
| 8 |
+
|
| 9 |
+
results = []
|
| 10 |
+
for item in soup.select(".views-row"):
|
| 11 |
+
a = item.select_one("a")
|
| 12 |
+
if not a:
|
| 13 |
+
continue
|
| 14 |
+
results.append({
|
| 15 |
+
"title": clean(a.text),
|
| 16 |
+
"agency": "CIA",
|
| 17 |
+
"date": None,
|
| 18 |
+
"snippet": None,
|
| 19 |
+
"url": "https://www.cia.gov" + a["href"]
|
| 20 |
+
})
|
| 21 |
+
return results
|