質問編集履歴

3

loop文修正

2018/12/08 11:08

投稿

hiro610
hiro610

スコア12

test CHANGED
File without changes
test CHANGED
@@ -106,6 +106,8 @@
106
106
 
107
107
  end
108
108
 
109
+ last_height = new_height
110
+
109
111
  end
110
112
 
111
113
  ```

2

自分で試したコードを追記

2018/12/08 11:08

投稿

hiro610
hiro610

スコア12

test CHANGED
File without changes
test CHANGED
@@ -71,3 +71,41 @@
71
71
 
72
72
 
73
73
  ```
74
+
75
+
76
+
77
+ 試してみたコードは以下です。
78
+
79
+ ```controller
80
+
81
+ 上記driver.navigate.to(url)の後ろに下記のコード追加
82
+
83
+ loop do
84
+
85
+ last_height = driver.execute_script("return document.body.scrollHeight")
86
+
87
+
88
+
89
+ driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
90
+
91
+
92
+
93
+ @video_titles = driver.find_elements(:xpath, "//a['video-title']")
94
+
95
+
96
+
97
+ Selenium::WebDriver::Wait.new(timeout: 10)
98
+
99
+
100
+
101
+ new_height = driver.execute_script("return document.body.scrollHeight")
102
+
103
+ if new_height == last_height
104
+
105
+ break
106
+
107
+ end
108
+
109
+ end
110
+
111
+ ```

1

URL変更

2018/12/08 11:05

投稿

hiro610
hiro610

スコア12

test CHANGED
File without changes
test CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
  driver = Selenium::WebDriver.for :chrome
38
38
 
39
- driver.get 'https://www.youtube.com/channel/UCoFLB_Gw_AoxUuuzKjXrc_Q/featured'
39
+ driver.get 'https://www.youtube.com/channel/UCoFLB_Gw_AoxUuuzKjXrc_Q/videos'
40
40
 
41
41
 
42
42