質問編集履歴
5
test
CHANGED
File without changes
|
test
CHANGED
@@ -114,4 +114,4 @@
|
|
114
114
|
|
115
115
|
|
116
116
|
|
117
|
-
shop_nameという
|
117
|
+
shop_nameというcsvファイルが作れない場合があります。
|
4
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,4 +102,16 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
|
105
|
-
例外処理が発生するのが
|
105
|
+
例外処理が発生するのが下記の場所です
|
106
|
+
|
107
|
+
for shop_temp in shop_span.find_all('a'):
|
108
|
+
|
109
|
+
shop_name = shop_temp.text.strip()
|
110
|
+
|
111
|
+
fetched_dataframes = pandas.io.html.read_html(shop)
|
112
|
+
|
113
|
+
fetched_dataframes[3].to_csv(shop_name)
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
shop_nameというテキストファイルが作れない場合があります。
|
3
j
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
下記のpythonのコードでexceptで例外処理をしています。
|
2
2
|
|
3
|
-
例外処理をしたあとの中をもう一度実行したいのですがどうすればよろしいでしょうか???
|
3
|
+
例外処理をしたあとのwhileの中をもう一度実行したいのですがどうすればよろしいでしょうか???
|
4
4
|
|
5
5
|
|
6
6
|
|
@@ -20,25 +20,21 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
#Chrome
|
24
|
-
|
25
|
-
#driver = webdriver.Chrome('/home/daichi/chromedriver')
|
26
|
-
|
27
23
|
driver = webdriver.PhantomJS()
|
28
24
|
|
29
25
|
driver.set_window_size(1024, 768)
|
30
26
|
|
31
|
-
driver.get('http://
|
27
|
+
driver.get('http://example.com')
|
32
28
|
|
33
29
|
|
34
30
|
|
35
31
|
|
36
32
|
|
37
|
-
input = driver.find_element_by_id("sa").send_keys(u"
|
33
|
+
input = driver.find_element_by_id("sa").send_keys(u"test")
|
38
34
|
|
39
35
|
time.sleep(3)
|
40
36
|
|
41
|
-
input = driver.find_element_by_id("sk").send_keys(u"
|
37
|
+
input = driver.find_element_by_id("sk").send_keys(u"test")
|
42
38
|
|
43
39
|
btn = driver.find_element_by_id("js-global-search-btn").click()
|
44
40
|
|
2
henkou
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,12 +1,54 @@
|
|
1
1
|
下記のpythonのコードでexceptで例外処理をしています。
|
2
2
|
|
3
|
-
例外処理をしたあと
|
3
|
+
例外処理をしたあとの中をもう一度実行したいのですがどうすればよろしいでしょうか???
|
4
4
|
|
5
5
|
|
6
6
|
|
7
7
|
```python
|
8
8
|
|
9
|
+
from selenium import webdriver
|
10
|
+
|
11
|
+
import chardet
|
12
|
+
|
13
|
+
from bs4 import BeautifulSoup
|
14
|
+
|
15
|
+
import pandas
|
16
|
+
|
17
|
+
import webbrowser
|
18
|
+
|
19
|
+
import time
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
#Chrome
|
24
|
+
|
25
|
+
#driver = webdriver.Chrome('/home/daichi/chromedriver')
|
26
|
+
|
27
|
+
driver = webdriver.PhantomJS()
|
28
|
+
|
29
|
+
driver.set_window_size(1024, 768)
|
30
|
+
|
31
|
+
driver.get('http://tabelog.com')
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
input = driver.find_element_by_id("sa").send_keys(u"銀座駅")
|
38
|
+
|
39
|
+
time.sleep(3)
|
40
|
+
|
41
|
+
input = driver.find_element_by_id("sk").send_keys(u"フレンチ")
|
42
|
+
|
43
|
+
btn = driver.find_element_by_id("js-global-search-btn").click()
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def get_data():
|
48
|
+
|
9
49
|
while True:
|
50
|
+
|
51
|
+
try:
|
10
52
|
|
11
53
|
data = driver.page_source.encode()
|
12
54
|
|
@@ -28,27 +70,13 @@
|
|
28
70
|
|
29
71
|
for shop_span in shop_list.find_all('h2', attrs={'class': 'display-name'}):
|
30
72
|
|
31
|
-
t
|
73
|
+
for shop_temp in shop_span.find_all('a'):
|
32
74
|
|
33
|
-
|
75
|
+
shop_name = shop_temp.text.strip()
|
34
76
|
|
35
|
-
shop_name = shop_temp.text.strip()
|
36
|
-
|
37
|
-
|
77
|
+
fetched_dataframes = pandas.io.html.read_html(shop)
|
38
78
|
|
39
79
|
fetched_dataframes[3].to_csv(shop_name)
|
40
|
-
|
41
|
-
except Exception:
|
42
|
-
|
43
|
-
f = open('failed.txt', 'a', newline='\n')
|
44
|
-
|
45
|
-
f.write(shop_name)
|
46
|
-
|
47
|
-
f.write('\n')
|
48
|
-
|
49
|
-
f.write(shop)
|
50
|
-
|
51
|
-
f.write('\n')
|
52
80
|
|
53
81
|
driver.back()
|
54
82
|
|
@@ -56,6 +84,24 @@
|
|
56
84
|
|
57
85
|
next.click()
|
58
86
|
|
87
|
+
except:
|
88
|
+
|
89
|
+
f = open('failed.txt', 'a', newline='\n')
|
90
|
+
|
91
|
+
f.write(shop_name)
|
92
|
+
|
93
|
+
f.write('\n')
|
94
|
+
|
95
|
+
f.write(shop)
|
96
|
+
|
97
|
+
f.write('\n')
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
get_data()
|
102
|
+
|
103
|
+
|
104
|
+
|
59
105
|
```
|
60
106
|
|
61
107
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,8 +7,6 @@
|
|
7
7
|
```python
|
8
8
|
|
9
9
|
while True:
|
10
|
-
|
11
|
-
try:
|
12
10
|
|
13
11
|
data = driver.page_source.encode()
|
14
12
|
|
@@ -30,13 +28,27 @@
|
|
30
28
|
|
31
29
|
for shop_span in shop_list.find_all('h2', attrs={'class': 'display-name'}):
|
32
30
|
|
33
|
-
|
31
|
+
try:
|
34
32
|
|
35
|
-
shop_
|
33
|
+
for shop_temp in shop_span.find_all('a'):
|
36
34
|
|
35
|
+
shop_name = shop_temp.text.strip()
|
36
|
+
|
37
|
-
fetched_dataframes = pandas.io.html.read_html(shop)
|
37
|
+
fetched_dataframes = pandas.io.html.read_html(shop)
|
38
38
|
|
39
39
|
fetched_dataframes[3].to_csv(shop_name)
|
40
|
+
|
41
|
+
except Exception:
|
42
|
+
|
43
|
+
f = open('failed.txt', 'a', newline='\n')
|
44
|
+
|
45
|
+
f.write(shop_name)
|
46
|
+
|
47
|
+
f.write('\n')
|
48
|
+
|
49
|
+
f.write(shop)
|
50
|
+
|
51
|
+
f.write('\n')
|
40
52
|
|
41
53
|
driver.back()
|
42
54
|
|
@@ -44,16 +56,8 @@
|
|
44
56
|
|
45
57
|
next.click()
|
46
58
|
|
47
|
-
|
59
|
+
```
|
48
60
|
|
49
|
-
f = open('failed.txt', 'a', newline='\n')
|
50
61
|
|
51
|
-
f.write(shop_name)
|
52
62
|
|
53
|
-
f.write('\n')
|
54
|
-
|
55
|
-
|
63
|
+
例外処理が発生するのが
|
56
|
-
|
57
|
-
f.write('\n')
|
58
|
-
|
59
|
-
```
|