質問編集履歴
3
コード加筆
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,4 +12,75 @@
|
|
12
12
|
このようにhorse_page_link()が正常に動作しなくなります。
|
13
13
|
|
14
14
|
どちらの関数も正常に動作させる方法が知りたいです。よろしくお願いいたします。
|
15
|
-
※どこが原因になっているかわからないため、ほぼ全文を載せています。見にくくなっていますがよろしくお願いいたします
|
15
|
+
※どこが原因になっているかわからないため、ほぼ全文を載せています。見にくくなっていますがよろしくお願いいたします
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
・上の画像のコード
|
20
|
+
```python
|
21
|
+
import requests
|
22
|
+
from bs4 import BeautifulSoup
|
23
|
+
import pandas as pd
|
24
|
+
import re
|
25
|
+
url = 'https://www.nankankeiba.com/race_info/2018092518070211.do'
|
26
|
+
|
27
|
+
def url_to_soup(url):
|
28
|
+
req = requests.get(url)
|
29
|
+
|
30
|
+
return BeautifulSoup(req.content, 'html.parser')
|
31
|
+
|
32
|
+
soup = url_to_soup(url)
|
33
|
+
|
34
|
+
def horse_page_link(url):
|
35
|
+
link_list = ['https://www.nankankeiba.com'+x.get('href') for x in soup.find_all('a', class_='tx-mid tx-low')]
|
36
|
+
|
37
|
+
return link_list
|
38
|
+
|
39
|
+
def get_race_data(url):
|
40
|
+
going_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][0:2]#予想レースの馬場状態
|
41
|
+
wether_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][3]#予想レースの天候
|
42
|
+
len_ = int(soup.find(id="race-data01-a").get_text().replace('\n','').split(' ')[3].replace(',','')[1:5])#予想レースの距離
|
43
|
+
|
44
|
+
|
45
|
+
wps_list=[]#予想レースの1,2,3位
|
46
|
+
wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-1chaku')[0]).split('</td>')[2]).replace('\n','')))
|
47
|
+
wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-2chaku')[0]).split('</td>')[2]).replace('\n','')))
|
48
|
+
wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-3chaku')[0]).split('</td>')[2]).replace('\n','')))
|
49
|
+
|
50
|
+
return going_, wether_, len_, wps_list
|
51
|
+
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
・下の画像のコード
|
56
|
+
```python
|
57
|
+
import requests
|
58
|
+
from bs4 import BeautifulSoup
|
59
|
+
import re
|
60
|
+
import pandas as pd
|
61
|
+
url = 'https://www.nankankeiba.com/result/2018092518070211.do'
|
62
|
+
|
63
|
+
def url_to_soup(url):
|
64
|
+
req = requests.get(url)
|
65
|
+
return BeautifulSoup(req.content, 'html.parser')
|
66
|
+
|
67
|
+
soup = url_to_soup(url)
|
68
|
+
|
69
|
+
def get_race_data(url):
|
70
|
+
going_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][0:2]#予想レースの馬場状態
|
71
|
+
wether_ = soup.find(id="race-data02").get_text().replace('\n','').split(';')[1].split(' ')[2][3]#予想レースの天候
|
72
|
+
len_ = int(soup.find(id="race-data01-a").get_text().replace('\n','').split(' ')[3].replace(',','')[1:5])#予想レースの距離
|
73
|
+
|
74
|
+
|
75
|
+
wps_list=[]#予想レースの1,2,3位
|
76
|
+
wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-1chaku')[0]).split('</td>')[2]).replace('\n','')))
|
77
|
+
wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-2chaku')[0]).split('</td>')[2]).replace('\n','')))
|
78
|
+
wps_list.append(int(re.sub('\<.*?\>','',str(soup.find_all('tr', class_='bg-3chaku')[0]).split('</td>')[2]).replace('\n','')))
|
79
|
+
|
80
|
+
return going_, wether_, len_, wps_list
|
81
|
+
|
82
|
+
def horse_page_link(url):
|
83
|
+
link_list = ['https://www.nankankeiba.com'+x.get('href') for x in soup.find_all('a', class_='tx-mid tx-low')]
|
84
|
+
|
85
|
+
return link_list
|
86
|
+
```
|
2
加筆
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,4 +11,5 @@
|
|
11
11
|
|
12
12
|
このようにhorse_page_link()が正常に動作しなくなります。
|
13
13
|
|
14
|
-
どちらの関数も正常に動作させる方法が知りたいです。よろしくお願いいたします。
|
14
|
+
どちらの関数も正常に動作させる方法が知りたいです。よろしくお願いいたします。
|
15
|
+
※どこが原因になっているかわからないため、ほぼ全文を載せています。見にくくなっていますがよろしくお願いいたします
|
1
加筆
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
jupyter notebookにて、別のノート
|
1
|
+
jupyter notebookにて、別のノートブックで実行すると、エラーが出る
|
body
CHANGED
File without changes
|