質問編集履歴
2
記載ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
下記のサイトから、店舗名と女の子の名前をリスト化したいです。
|
2
2
|
|
3
|
-
https://www.
|
3
|
+
https://www.***********/girllist/
|
4
4
|
|
5
5
|
|
6
6
|
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
browser = webdriver.Chrome()
|
20
20
|
|
21
|
-
url = 'https://www.
|
21
|
+
url = 'https://www.**************:/'
|
22
22
|
|
23
23
|
browser.get(url)
|
24
24
|
|
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
browser.get('https://www.
|
35
|
+
browser.get('https://www.*********************:/girllist/')
|
36
36
|
|
37
37
|
elems = browser.find_elements_by_class_name('girllistimg')
|
38
38
|
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,48 +1,90 @@
|
|
1
|
-
下記のサイトから
|
1
|
+
下記のサイトから、店舗名と女の子の名前をリスト化したいです。
|
2
2
|
|
3
|
-
https://
|
3
|
+
https://www.cityheaven.net/tokyo/A1303/A130301/tokyo_guranop/girllist/
|
4
4
|
|
5
5
|
|
6
6
|
|
7
7
|
手探りで下記のようなコードを記載しました。
|
8
8
|
|
9
|
+
|
10
|
+
|
9
11
|
```ここに言語を入力
|
10
12
|
|
11
13
|
from selenium import webdriver
|
14
|
+
|
15
|
+
import pandas as pd
|
12
16
|
|
13
17
|
|
14
18
|
|
15
19
|
browser = webdriver.Chrome()
|
16
20
|
|
17
|
-
url = 'https://
|
21
|
+
url = 'https://www.cityheaven.net/tokyo/A1303/A130301/tokyo_guranop/'
|
18
22
|
|
19
23
|
browser.get(url)
|
20
24
|
|
21
25
|
|
22
26
|
|
23
|
-
|
27
|
+
elem_urls = []
|
28
|
+
|
29
|
+
girls = []
|
30
|
+
|
31
|
+
shop_names = []
|
24
32
|
|
25
33
|
|
26
34
|
|
35
|
+
browser.get('https://www.cityheaven.net/tokyo/A1303/A130301/tokyo_guranop/girllist/')
|
36
|
+
|
27
|
-
elems = browser.find_elements_by_class_name('
|
37
|
+
elems = browser.find_elements_by_class_name('girllistimg')
|
28
38
|
|
29
39
|
for elem in elems:
|
30
40
|
|
31
|
-
elem
|
41
|
+
elem_url = elem.find_element_by_tag_name("a").get_attribute("href")
|
32
42
|
|
33
|
-
|
43
|
+
elem_urls.append(elem_url)
|
34
44
|
|
35
|
-
elem
|
45
|
+
for elem_url in elem_urls:
|
36
46
|
|
37
|
-
|
47
|
+
browser.get(elem_url)
|
38
48
|
|
39
|
-
|
49
|
+
name_elems = browser.find_elements_by_id('profiles')
|
40
50
|
|
51
|
+
for name_elem in name_elems:
|
52
|
+
|
53
|
+
td_name = name_elem.find_element_by_tag_name('td')
|
54
|
+
|
55
|
+
name = td_name.text
|
56
|
+
|
57
|
+
girls.append(name)
|
58
|
+
|
59
|
+
elem_shop = browser.find_element_by_class_name('shopname')
|
60
|
+
|
61
|
+
elem_shop_name = elem_shop.find_element_by_tag_name('h1')
|
62
|
+
|
63
|
+
shop_name = elem_shop_name.text
|
64
|
+
|
65
|
+
shop_names.append(shop_name)
|
66
|
+
|
67
|
+
|
68
|
+
|
41
|
-
|
69
|
+
df = pd.DataFrame()
|
70
|
+
|
71
|
+
df['店舗名'] = shop_names
|
72
|
+
|
73
|
+
df['名前'] = girls
|
74
|
+
|
75
|
+
df['url'] = elem_urls
|
76
|
+
|
77
|
+
df.to_csv('test_file.csv',index=None)
|
42
78
|
|
43
79
|
|
44
80
|
|
45
81
|
```
|
82
|
+
|
83
|
+
下記のエラーが発生してしまいました。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
|
46
88
|
|
47
89
|
|
48
90
|
|