回答編集履歴
2
誤字修正
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
配列に テキストではなく hrefを取得して
|
2
2
|
|
3
|
-
navigateする
|
3
|
+
navigateするのは 如何でしょうか?
|
4
4
|
|
5
5
|
|
6
6
|
|
1
コード追加
test
CHANGED
@@ -1,3 +1,115 @@
|
|
1
1
|
配列に テキストではなく hrefを取得して
|
2
2
|
|
3
3
|
navigateするには 如何でしょうか?
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```Ruby
|
8
|
+
|
9
|
+
def main()
|
10
|
+
|
11
|
+
headers = ['sent_on','title','sent','opened','click','error','unsubscribe']
|
12
|
+
|
13
|
+
@title = 'benchmark'
|
14
|
+
|
15
|
+
@time = Time.new.strftime("%Y_%m_%d")
|
16
|
+
|
17
|
+
@filename = "#{@title}_new_#{@time}.csv"
|
18
|
+
|
19
|
+
CSV.open("#{@filename}", "w", write_headers: true) {|csv| csv << headers }
|
20
|
+
|
21
|
+
@stdout.info("#{@filename} is created")
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
26
|
+
|
27
|
+
# options.add_argument('--headless')
|
28
|
+
|
29
|
+
options.add_argument('--no-sandbox')
|
30
|
+
|
31
|
+
options.add_argument('--disable-gpu')
|
32
|
+
|
33
|
+
options.add_argument('--window-size=1280,1024')
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
wait = Selenium::WebDriver::Wait.new(timeout: 10)
|
38
|
+
|
39
|
+
driver = Selenium::WebDriver.for :chrome, options: options
|
40
|
+
|
41
|
+
driver.navigate.to "https://ui.benchmarkemail.com/jp/login"
|
42
|
+
|
43
|
+
# ログイン情報入力後、ログインボタン押下
|
44
|
+
|
45
|
+
driver.find_element(:id, 'login').send_keys('manabu.goto.1@helte-corp.com');sleep 1
|
46
|
+
|
47
|
+
driver.find_element(:id, 'password').send_keys('Helte0322');sleep 1
|
48
|
+
|
49
|
+
driver.find_element(:xpath, '//*[@id="login-page"]/div/div[2]/div/div[4]/fieldset[3]/div[1]/a').click;sleep 2
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
# レポートページに遷移
|
54
|
+
|
55
|
+
driver.find_element(:xpath, '//*[@id="sideMenu"]/div[2]/ul/li[4]/span').click;sleep 1
|
56
|
+
|
57
|
+
driver.find_element(:xpath, '//*[@id="linkEmailReports_desktop"]/a').click;sleep 1
|
58
|
+
|
59
|
+
# 各メールレポートの詳細
|
60
|
+
|
61
|
+
links = driver.find_elements(:class, 'title')
|
62
|
+
|
63
|
+
mail_links = links.each_slice(2).map(&:first)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
hrefs = []
|
68
|
+
|
69
|
+
mail_links.each do |link|
|
70
|
+
|
71
|
+
hrefs.push(link.find_element(:tag_name, 'a').attribute('href'))
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
hrefs.each do |link|
|
80
|
+
|
81
|
+
begin
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
driver.navigate.to link
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
params = get_params(driver,wait)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
if params.nil?
|
94
|
+
|
95
|
+
@stdout.fatal("params is nil")
|
96
|
+
|
97
|
+
next
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
rescue => e
|
102
|
+
|
103
|
+
@stdout.fatal(e)
|
104
|
+
|
105
|
+
driver.close
|
106
|
+
|
107
|
+
next
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
```
|