質問編集履歴

3

コード加筆

2018/09/30 14:01

投稿

onushinosenzo
onushinosenzo

スコア22

test CHANGED
File without changes
test CHANGED
@@ -27,3 +27,145 @@
27
27
  どちらの関数も正常に動作させる方法が知りたいです。よろしくお願いいたします。
28
28
 
29
29
  ※どこが原因になっているかわからないため、ほぼ全文を載せています。見にくくなっていますがよろしくお願いいたします
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ ・上の画像のコード
38
+
39
+ ```python
40
+
41
+ import requests
42
+
43
+ from bs4 import BeautifulSoup
44
+
45
+ import pandas as pd
46
+
47
+ import re
48
+
49
+ url = 'https://www.nankankeiba.com/race_info/2018092518070211.do'
50
+
51
+
52
+
53
+ def url_to_soup(url):
54
+
55
+ req = requests.get(url)
56
+
57
+
58
+
59
+ return BeautifulSoup(req.content, 'html.parser')
60
+
61
+
62
+
63
+ soup = url_to_soup(url)
64
+
65
+
66
+
67
+ def horse_page_link(url):
68
+
69
+ link_list = ['https://www.nankankeiba.com'+x.get('href') for x in soup.find_all('a', class_='tx-mid tx-low')]
70
+
71
+
72
+
73
+ return link_list
74
+
75
+
76
+
77
+ def get_race_data(url):
78
+
79
+ going_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][0:2]#予想レースの馬場状態
80
+
81
+ wether_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][3]#予想レースの天候
82
+
83
+ len_ = int(soup.find(id="race-data01-a").get_text().replace('\n','').split(' ')[3].replace(',','')[1:5])#予想レースの距離
84
+
85
+
86
+
87
+
88
+
89
+ wps_list=[]#予想レースの1,2,3位
90
+
91
+ wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-1chaku')[0]).split('</td>')[2]).replace('\n','')))
92
+
93
+ wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-2chaku')[0]).split('</td>')[2]).replace('\n','')))
94
+
95
+ wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-3chaku')[0]).split('</td>')[2]).replace('\n','')))
96
+
97
+
98
+
99
+ return going_, wether_, len_, wps_list
100
+
101
+
102
+
103
+ ```
104
+
105
+
106
+
107
+
108
+
109
+ ・下の画像のコード
110
+
111
+ ```python
112
+
113
+ import requests
114
+
115
+ from bs4 import BeautifulSoup
116
+
117
+ import re
118
+
119
+ import pandas as pd
120
+
121
+ url = 'https://www.nankankeiba.com/result/2018092518070211.do'
122
+
123
+
124
+
125
+ def url_to_soup(url):
126
+
127
+ req = requests.get(url)
128
+
129
+ return BeautifulSoup(req.content, 'html.parser')
130
+
131
+
132
+
133
+ soup = url_to_soup(url)
134
+
135
+
136
+
137
+ def get_race_data(url):
138
+
139
+ going_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][0:2]#予想レースの馬場状態
140
+
141
+ wether_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][3]#予想レースの天候
142
+
143
+ len_ = int(soup.find(id="race-data01-a").get_text().replace('\n','').split(' ')[3].replace(',','')[1:5])#予想レースの距離
144
+
145
+
146
+
147
+
148
+
149
+ wps_list=[]#予想レースの1,2,3位
150
+
151
+ wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-1chaku')[0]).split('</td>')[2]).replace('\n','')))
152
+
153
+ wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-2chaku')[0]).split('</td>')[2]).replace('\n','')))
154
+
155
+ wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-3chaku')[0]).split('</td>')[2]).replace('\n','')))
156
+
157
+
158
+
159
+ return going_, wether_, len_, wps_list
160
+
161
+
162
+
163
+ def horse_page_link(url):
164
+
165
+ link_list = ['https://www.nankankeiba.com'+x.get('href') for x in soup.find_all('a', class_='tx-mid tx-low')]
166
+
167
+
168
+
169
+ return link_list
170
+
171
+ ```

2

加筆

2018/09/30 14:01

投稿

onushinosenzo
onushinosenzo

スコア22

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,5 @@
25
25
 
26
26
 
27
27
  どちらの関数も正常に動作させる方法が知りたいです。よろしくお願いいたします。
28
+
29
+ ※どこが原因になっているかわからないため、ほぼ全文を載せています。見にくくなっていますがよろしくお願いいたします

1

加筆

2018/09/30 13:41

投稿

onushinosenzo
onushinosenzo

スコア22

test CHANGED
@@ -1 +1 @@
1
- jupyter notebookにて、別のノートとエラーが出る
1
+ jupyter notebookにて、別のノートブックで実行するエラーが出る
test CHANGED
File without changes