-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlatlong.py
More file actions
41 lines (34 loc) · 1.21 KB
/
latlong.py
File metadata and controls
41 lines (34 loc) · 1.21 KB
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
from bs4 import BeautifulSoup as BS
import requests
from latlong_util import cleanName, processCoords
original_site = requests.get("http://www.gero3p.sakura.ne.jp/files/jisa/fukusima.html")
original_site.encoding = original_site.apparent_encoding
original_site.text
site_soup = BS(original_site.text, "html.parser")
# print(site_soup.table)
allTables = site_soup.find_all("table")
printed = 0
printedHowMany = 2
cityData = []
latLongData = []
for table in allTables:
allRows = table.find_all("tr")
for thisRow in allRows:
headercols = thisRow.find_all("th")
datacols = thisRow.find_all("td")
if len(datacols) == 0:
datacols
# print("header----------------------")
elif len(headercols) == 1:
if datacols[0].text == "":
cityData.append(cleanName(headercols[0].text))
latLongData.append(processCoords(datacols[3].text))
else:
cityData.append(cleanName(datacols[0].text))
latLongData.append(processCoords(datacols[3].text))
else:
cityData.append(cleanName(datacols[0].text))
latLongData.append(processCoords(datacols[3].text))
outputFile = open("data-latlong/latLong.dat", "w+")
outputFile.write(str(cityData))
outputFile.write(str(latLongData))