質問編集履歴

4

ソースコードの追加

2018/07/24 05:52

投稿

cureseven
cureseven

スコア18

test CHANGED
File without changes
test CHANGED
@@ -61,3 +61,119 @@
61
61
  全部貼ります
62
62
 
63
63
  ![イメージ説明](507df2d3843683da01e84a649df78f38.png)
64
+
65
+
66
+
67
+ ```python
68
+
69
+ #タイトルを引っ張てくる
70
+
71
+ import requests,bs4
72
+
73
+ import codecs
74
+
75
+ import os
76
+
77
+ import glob
78
+
79
+
80
+
81
+ # トップページ
82
+
83
+ res = requests.get('https://dictionary.goo.ne.jp/dialect/')
84
+
85
+ res.raise_for_status() # 例外発生
86
+
87
+ soup = bs4.BeautifulSoup(res.text, "html.parser") # HTMLを取ってくる
88
+
89
+ elems = soup.find_all("ul",class_="list-simple-d") # 指定して取り出して来た文字列
90
+
91
+ box = [] # ul内のもの全ての配列
92
+
93
+ pref = [] # 都道府県名の配列
94
+
95
+
96
+
97
+ for elem in elems:
98
+
99
+ prefname = elem.getText()
100
+
101
+ str = prefname.replace("¥n"," ").split() # 改行をスペースに変換した文字列
102
+
103
+ for w in str:
104
+
105
+ box.append(w) #boxにwを追加
106
+
107
+ if len(w) < 5:
108
+
109
+ pref.append(w) #prefに都道府県名を追加
110
+
111
+ # print(pref)
112
+
113
+ # print(w)
114
+
115
+
116
+
117
+ for i in pref:
118
+
119
+ for j in ['1','2','3','4','5','6','7','8','9']:
120
+
121
+ title = "https://dictionary.goo.ne.jp/srch/dialect/" + i + "/m9p" + j + "u/"
122
+
123
+ # print(type(j)) #->str
124
+
125
+ # print(title)
126
+
127
+ for k in range(9):
128
+
129
+ # print(k)
130
+
131
+ # num = str(k)
132
+
133
+ # title2 = "https://dictionary.goo.ne.jp/srch/dialect/" + i + "/m9p" + str(k) + "u/" #->できない!
134
+
135
+ # title2 = "https://dictionary.goo.ne.jp/srch/dialect/%s/m9p%du/" % i,k
136
+
137
+ title2 = "https://dictionary.goo.ne.jp/srch/dialect/" + i + "/m9p%du/" % k
138
+
139
+ print(title2)
140
+
141
+
142
+
143
+
144
+
145
+ print(type(range(9))) #-> range
146
+
147
+ # preffilename = w + '.txt'
148
+
149
+ # file = open(preffilename,'w')
150
+
151
+ # elems = soup.find_all("dt", class_="title search-ttl-a")
152
+
153
+ # for elem in elems:
154
+
155
+ # print(elem.getText())
156
+
157
+ # f.write(elem.getText())
158
+
159
+ #
160
+
161
+ # os.chdir("/test_dir/dir_A")
162
+
163
+ # preffilelist = glob.glob("./*")
164
+
165
+ # print(preffilelist)
166
+
167
+ # f.close
168
+
169
+
170
+
171
+
172
+
173
+ # print(pref)
174
+
175
+ # print(len(pref))
176
+
177
+
178
+
179
+ ```

3

画像の追加

2018/07/24 05:52

投稿

cureseven
cureseven

スコア18

test CHANGED
File without changes
test CHANGED
@@ -55,3 +55,9 @@
55
55
  pythonのバージョンはPython 3.7.0です.
56
56
 
57
57
  ![イメージ説明](ae3342de6864fe29f2dc7635c45e8023.png)
58
+
59
+
60
+
61
+ 全部貼ります
62
+
63
+ ![イメージ説明](507df2d3843683da01e84a649df78f38.png)

2

前後のソースコードの追加

2018/07/24 05:49

投稿

cureseven
cureseven

スコア18

test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,9 @@
42
42
 
43
43
  ```python
44
44
 
45
+ for k in range(9):
46
+
45
- title2 = "https://dictionary.goo.ne.jp/srch/dialect/" + i + "/m9p%du/" % k
47
+      title2 = "https://dictionary.goo.ne.jp/srch/dialect/" + i + "/m9p%du/" % k
46
48
 
47
49
  ```
48
50
 

1

誤字

2018/07/24 05:47

投稿

cureseven
cureseven

スコア18

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```python
4
4
 
5
- for i in range(9):
5
+ for k in range(9):
6
6
 
7
7
     title2 = "https://dictionary.goo.ne.jp/srch/dialect/" + i + "/m9p" + str(k) + "u/"
8
8