-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_rdb_shop_location.py
55 lines (47 loc) · 1.25 KB
/
get_rdb_shop_location.py
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
from bs4 import BeautifulSoup
import urllib.request as req
import sys
import datetime
import json
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
#
# url2uid
# replace /u/xxxx.html to xxxx
#
def url2uid(url):
return url.replace('/u/','').replace('.html', '')
#
# print shop infomation
#
def printShop(num):
url = 'https://supleks.jp/s/' + str(num) + '.html'
try:
res = req.urlopen(url)
soup = BeautifulSoup(res, "html.parser")
if soup is None :
sys.stderr.write ('html.paser error, num=' + format(num) + '\n')
return
scriptNode = soup.find('script', type="application/ld+json")
if scriptNode is None :
print("scriptNode is None")
retutn
scriptJson = json.loads(scriptNode.string)
if scriptJson is None :
print ("scriptJson is None")
else :
latitude = scriptJson['geo']['latitude']
longitude = scriptJson['geo']['longitude']
# output shop location record
shop = format(num) + '\t' + latitude + '\t' +longitude
try:
print(shop.encode('cp932','ignore').decode('cp932'))
except UnicodeError as e:
print("Unicode error", e)
except:
sys.stderr.write ('\n' + 'exception, num=' + format(num) + '\n')
pass
# メインメソッド
args = sys.argv
for num in range(int(args[1]), int(args[2]) + 1):
printShop(num)