回答編集履歴

7

参考情報を追加

2018/06/10 14:32

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -143,3 +143,5 @@
143
143
  0. [itertools.filterfalse](https://docs.python.jp/3/library/itertools.html#itertools.filterfalse)
144
144
 
145
145
  0. [Pythonスクレイピング:同じ名前のクラス内での識別](https://teratail.com/questions/120415)
146
+
147
+ 0. [:nth-of-type()](https://developer.mozilla.org/ja/docs/Web/CSS/:nth-of-type)

6

追記

2018/06/10 14:32

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -140,4 +140,6 @@
140
140
 
141
141
  ◇参考情報
142
142
 
143
- [itertools.filterfalse](https://docs.python.jp/3/library/itertools.html#itertools.filterfalse)
143
+ 0. [itertools.filterfalse](https://docs.python.jp/3/library/itertools.html#itertools.filterfalse)
144
+
145
+ 0. [Pythonスクレイピング:同じ名前のクラス内での識別](https://teratail.com/questions/120415)

5

追記

2018/06/10 13:55

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -63,3 +63,81 @@
63
63
  ◇参考情報
64
64
 
65
65
  [[netkeiba] の検索結果](https://teratail.com/questions/search?q=netkeiba&conditions=and)
66
+
67
+
68
+
69
+ ---
70
+
71
+
72
+
73
+ 218/06/10追記
74
+
75
+ ```Python
76
+
77
+ # -*- coding: utf-8 -*-
78
+
79
+ from itertools import filterfalse
80
+
81
+ from urllib.request import urlopen
82
+
83
+ from bs4 import BeautifulSoup
84
+
85
+
86
+
87
+
88
+
89
+ def main() -> None:
90
+
91
+ # 指定するURL
92
+
93
+ URL = "http://race.netkeiba.com/?pid=payback_list&id=p2018050301"
94
+
95
+ html = urlopen(URL)
96
+
97
+ soup = BeautifulSoup(html, "html.parser")
98
+
99
+ print(soup)
100
+
101
+ print('#' * 60)
102
+
103
+
104
+
105
+ for tr in soup.select("table.race_table_01 > tr.bml1"):
106
+
107
+ for rank in filterfalse(lambda x: x.renderContents().decode() != "1", tr.select("td:nth-of-type(1)")):
108
+
109
+ for popular in tr.select("td:nth-of-type(12)"):
110
+
111
+ print(popular.renderContents().decode())
112
+
113
+ break
114
+
115
+ # filterfalseは以下の行と同じです
116
+
117
+ #for rank in tr.select("td:nth-of-type(1)"):
118
+
119
+ # if rank.renderContents().decode() != "1":
120
+
121
+ # continue
122
+
123
+ # for popular in tr.select("td:nth-of-type(12)"):
124
+
125
+ # print(popular.renderContents().decode())
126
+
127
+ # break
128
+
129
+
130
+
131
+
132
+
133
+ if __name__ == '__main__':
134
+
135
+ main()
136
+
137
+
138
+
139
+ ```
140
+
141
+ ◇参考情報
142
+
143
+ [itertools.filterfalse](https://docs.python.jp/3/library/itertools.html#itertools.filterfalse)

4

追記

2018/06/10 13:53

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- クラス指定が色情報を取得するコードになっていますが・・・
5
+ クラス指定が列:人気を取得するコードになっていますが・・・
6
6
 
7
7
 
8
8
 

3

追記

2018/06/10 12:35

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
 
42
42
 
43
- for table in soup.find_all('table', class_='race_table_01 nk_tb_common'):
43
+ for table in soup.find_all('table', class_='race_table_01'):
44
44
 
45
45
  for val in table.find_all('td', class_='txt_r'):
46
46
 

2

追記

2018/06/10 12:32

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -59,3 +59,7 @@
59
59
 
60
60
 
61
61
  ```
62
+
63
+ ◇参考情報
64
+
65
+ [[netkeiba] の検索結果](https://teratail.com/questions/search?q=netkeiba&conditions=and)

1

追記

2018/06/10 12:30

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -1,4 +1,6 @@
1
1
  > market = soup.find('td', class_='cellcolor_1')
2
+
3
+
2
4
 
3
5
  クラス指定が色情報を取得するコードになっていますが・・・
4
6