質問するログイン新規登録

質問編集履歴

4

ファイルを読みこっむことができたためエラーメッセージとソースコードを修正しました

2019/12/04 08:47

投稿

aqws
aqws

スコア8

title CHANGED
File without changes
body CHANGED
@@ -3,9 +3,11 @@
3
3
 
4
4
  ###発生しているエラーメッセージ
5
5
  Traceback (most recent call last):
6
- File "pysample14.py", line 27, in <module>
6
+ File "pysample14.py", line 40, in <module>
7
- text = text3.txt
7
+ latlons = get_lat_lon_from_address(data1);
8
+ File "pysample14.py", line 19, in get_lat_lon_from_address
9
+ raise ValueError(f"Invalid address submitted. {address}")
8
- NameError: name 'text3' is not defined
10
+ ValueError: Invalid address submitted. [
9
11
 
10
12
  ###ソースコード
11
13
 
@@ -31,8 +33,11 @@
31
33
  time.sleep(10)
32
34
  return latlons
33
35
 
34
- text = text.txt  #text.txtとは使用するテキストファイル
36
+ f = open('text.txt')  #text.txtとは使用するテキストファイル
37
+ data1 = f.read()
38
+
39
+
35
- latlons = get_lat_lon_from_address([str(text)]);
40
+ latlons = get_lat_lon_from_address(data1);
36
41
  print(latlons);
37
42
 
38
43
  ### 使用するテキストファイルの中身
@@ -43,6 +48,7 @@
43
48
 
44
49
  この住所の部分のみを反応させてどうにか緯度経度に変換できないか考えていましたが、住所のみを一つずつ反応させて緯度経度に変換する方法がわからずここで止まってしまっています
45
50
 
51
+
46
52
  ### 補足情報(FW/ツールのバージョンなど)
47
53
 
48
- Atomとコマンドプロンプトを使ています
54
+ Atomとコマンドプロンプトを使用しています

3

タグを変更しました

2019/12/04 08:47

投稿

aqws
aqws

スコア8

title CHANGED
File without changes
body CHANGED
File without changes

2

エラーメッセージを追加しました。

2019/12/02 07:22

投稿

aqws
aqws

スコア8

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,12 @@
1
1
  ### 前提・実現したいこと
2
2
  PHPを用いてテキストファイルに書いてある住所から緯度経度を取得しマッピングしたいと考えています
3
+
4
+ ###発生しているエラーメッセージ
5
+ Traceback (most recent call last):
6
+ File "pysample14.py", line 27, in <module>
7
+ text = text3.txt
8
+ NameError: name 'text3' is not defined
9
+
3
10
  ###ソースコード
4
11
 
5
12
  import requests

1

ソースコードを追加しました

2019/12/02 07:03

投稿

aqws
aqws

スコア8

title CHANGED
File without changes
body CHANGED
@@ -1,14 +1,40 @@
1
1
  ### 前提・実現したいこと
2
- PHPテキストファイルに書いてある住所から緯度経度を取得しマッピングしたいと考えています
2
+ PHPを用いてテキストファイルに書いてある住所から緯度経度を取得しマッピングしたいと考えています
3
+ ###ソースコード
3
4
 
5
+ import requests
6
+ from bs4 import BeautifulSoup
7
+ import time
8
+ from tqdm import tqdm
4
9
 
10
+ def get_lat_lon_from_address(address_l):
11
+
12
+ url = 'http://www.geocoding.jp/api/'
13
+ latlons = []
14
+ for address in tqdm(address_l):
15
+ payload = {'q': address}
16
+ r = requests.get(url, params=payload)
17
+ ret = BeautifulSoup(r.content,'lxml')
18
+ if ret.find('error'):
19
+ raise ValueError(f"Invalid address submitted. {address}")
20
+ else:
21
+ lat = ret.find('lat').string
22
+ lon = ret.find('lng').string
23
+ latlons.append([lat,lon])
24
+ time.sleep(10)
25
+ return latlons
26
+
27
+ text = text.txt  #text.txtとは使用するテキストファイル
28
+ latlons = get_lat_lon_from_address([str(text)]);
29
+ print(latlons);
30
+
5
31
  ### 使用するテキストファイルの中身
6
32
 
7
33
  ['東京タワー(東京都港区芝公園4-2-8)', '東京スカイツリー(東京都墨田区押上1丁目1‐2)', '東京駅(東京都千代田区丸の内1)', '上野動物園(東京都台東区上野公園9)']
8
34
 
9
35
  ### 試したこと
10
36
 
11
- この住所の部分のみを反応させてどうにか緯度経度に変換できないか考えていましたがどうも見当かずせん
37
+ この住所の部分のみを反応させてどうにか緯度経度に変換できないか考えていましたが、住所のみを一つずつ反応させて緯度経度変換する方法ここで止ってしまっていま
12
38
 
13
39
  ### 補足情報(FW/ツールのバージョンなど)
14
40