質問編集履歴
1
該当のソースコードを追加
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -8,13 +8,46 @@
|
|
|
8
8
|
|
|
9
9
|
### 該当のソースコード
|
|
10
10
|
|
|
11
|
-
```
|
|
11
|
+
```python
|
|
12
|
+
# Chromeドライバの自動更新
|
|
13
|
+
import chromedriver_binary_sync
|
|
14
|
+
chromedriver_binary_sync.download()
|
|
15
|
+
|
|
16
|
+
# 必要ライブラリのインポート
|
|
17
|
+
from selenium import webdriver
|
|
18
|
+
from selenium.webdriver.common.by import By
|
|
19
|
+
from selenium.webdriver.common.keys import Keys
|
|
20
|
+
import chromedriver_binary
|
|
21
|
+
import time
|
|
22
|
+
import pandas as pd
|
|
23
|
+
|
|
24
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
25
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
26
|
+
|
|
27
|
+
#ブラウザの設定
|
|
28
|
+
options = webdriver.ChromeOptions()
|
|
29
|
+
options.add_argument('--headless')
|
|
30
|
+
options.add_argument('--no-sandbox')
|
|
31
|
+
options.add_argument('--disable-dev-shm-usage')
|
|
32
|
+
|
|
33
|
+
#ブラウザの起動
|
|
34
|
+
browser = webdriver.Chrome(options=options)
|
|
35
|
+
wait = WebDriverWait(browser, 3)
|
|
36
|
+
|
|
37
|
+
url = 'https://jp.mercari.com/item/m66669659367'
|
|
38
|
+
|
|
39
|
+
browser.get(url)
|
|
40
|
+
time.sleep(5)
|
|
41
|
+
|
|
42
|
+
#要素取得
|
|
12
|
-
element = browser.find_element(By.CSS_SELECTOR, '#item-info > section:nth-child(1) > section:nth-child(3) > div > pre:nth-child(2)'
|
|
43
|
+
element = browser.find_element(By.CSS_SELECTOR, '#item-info > section:nth-child(1) > section:nth-child(3) > div > pre:nth-child(2)').text
|
|
44
|
+
#element = browser.find_element(By.CSS_SELECTOR, '#item-info > section:nth-child(1) > div.mer-spacing-b-12 > div > div > h1').text
|
|
45
|
+
print('売れてからの経過時間 : ' + element)
|
|
13
46
|
```
|
|
14
47
|
|
|
15
48
|
### 試したこと
|
|
16
49
|
そのままセレクターをコピーすると
|
|
17
|
-
```
|
|
50
|
+
```python
|
|
18
51
|
'#item-info > section:nth-child(1) > section:nth-child(3) > div > pre.merText.small__5616e150.primary__5616e150.bold__5616e150'
|
|
19
52
|
```
|
|
20
53
|
ですが、2連続アンダースコアが入っているため、nth-childで置き換えましたが、取得ができませんでした
|