回答編集履歴
3
間違いを修正
answer
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
取得先のHTMLを見て適宜変えてください。
|
14
14
|
|
15
15
|
```python
|
16
|
-
elements = driver.find_elements_by_css_selector("body > table tr:nth-of-type(10) tr:nth-of-type(2n+3) td:nth-of-type(2) b:first-of-type")
|
16
|
+
elements = driver.find_elements_by_css_selector("body > table tr:nth-of-type(10) tr tr:nth-of-type(2n+3) td:nth-of-type(2) b:first-of-type")
|
17
17
|
```
|
18
18
|
|
19
19
|
ご参考まで。
|
2
説明を追記
answer
CHANGED
@@ -6,7 +6,14 @@
|
|
6
6
|
- [nth-child() - CSS: カスケーディングスタイルシート - MDN Web Docs](https://developer.mozilla.org/ja/docs/Web/CSS/:nth-child)
|
7
7
|
|
8
8
|
```python
|
9
|
-
elements = driver.find_elements_by_css_selector("table tbody tr:nth-of-type(10) td table tbody tr td table tbody tr:nth-of-type(2n+3) td:nth-of-type(2) b:first-of-type")
|
9
|
+
elements = driver.find_elements_by_css_selector("body > table > tbody > tr:nth-of-type(10) > td > table > tbody > tr > td > table > tbody > tr:nth-of-type(2n+3) > td:nth-of-type(2) > b:first-of-type")
|
10
10
|
```
|
11
11
|
|
12
|
+
実際はXPathほど厳密に辿らなくてもいいので、以下のような感じでしょうか。
|
13
|
+
取得先のHTMLを見て適宜変えてください。
|
14
|
+
|
15
|
+
```python
|
16
|
+
elements = driver.find_elements_by_css_selector("body > table tr:nth-of-type(10) tr:nth-of-type(2n+3) td:nth-of-type(2) b:first-of-type")
|
17
|
+
```
|
18
|
+
|
12
19
|
ご参考まで。
|
1
Selenium用に変更
answer
CHANGED
@@ -5,12 +5,8 @@
|
|
5
5
|
- [nth-of-type() - CSS: カスケーディングスタイルシート - MDN Web Docs](https://developer.mozilla.org/ja/docs/Web/CSS/:nth-of-type)
|
6
6
|
- [nth-child() - CSS: カスケーディングスタイルシート - MDN Web Docs](https://developer.mozilla.org/ja/docs/Web/CSS/:nth-child)
|
7
7
|
|
8
|
-
どのライブラリを使って
|
9
|
-
らっしゃるかわからないので、とりあえずBeautiful Soupでの例を挙げておきます。
|
10
|
-
Seleniumでも`driver.find_elements_by_css_selector()`などで同様のことができます。
|
11
|
-
|
12
8
|
```python
|
13
|
-
elements =
|
9
|
+
elements = driver.find_elements_by_css_selector("table tbody tr:nth-of-type(10) td table tbody tr td table tbody tr:nth-of-type(2n+3) td:nth-of-type(2) b:first-of-type")
|
14
10
|
```
|
15
11
|
|
16
12
|
ご参考まで。
|