rakuten_securities_scraper 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -2
- data/Gemfile.lock +3 -1
- data/README.md +1 -1
- data/lib/rakuten_securities_scraper.rb +69 -3
- data/lib/rakuten_securities_scraper/version.rb +1 -1
- data/rakuten_securities_scraper.gemspec +4 -0
- metadata +59 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16a2376da1337dfc32d2b319e40110fe7a70448d6c86f77e096b11c7673349e7
|
4
|
+
data.tar.gz: 409ee19906a3ea99dff6d41e67460443821a2da9d6e9cb38248ff75c95823b9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b2dead8449bfe20ed0b794ddc4ef8fe715ac68894b4f4939a59850b1b7d112ba903fca01245093ce57463a8b3f2355b82ad1d64475193caabd3e38f9086e9d6
|
7
|
+
data.tar.gz: 573093ff0c9c25471f1c15f5a09be55944ce2edbb22f3ccbe9a33783cab6555d9d4913c0c4c7ff0efd71236fb3777e926475c46d36dfadcf0e3579e8f8c8cb2c
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rakuten_securities_scraper (0.1.
|
4
|
+
rakuten_securities_scraper (0.1.4)
|
5
|
+
selenium-webdriver (~> 3.142.7)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -50,6 +51,7 @@ PLATFORMS
|
|
50
51
|
ruby
|
51
52
|
|
52
53
|
DEPENDENCIES
|
54
|
+
bundler (~> 2.0)
|
53
55
|
rake (~> 12.0)
|
54
56
|
rakuten_securities_scraper!
|
55
57
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -69,7 +69,7 @@ Or install it yourself as:
|
|
69
69
|
|
70
70
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
71
71
|
|
72
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org/gems/rakuten_securities_scraper).
|
73
73
|
|
74
74
|
## Contributing
|
75
75
|
|
@@ -11,6 +11,72 @@ module RakutenSecuritiesScraper
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
+
def login
|
15
|
+
driver = get_selenium_driver(:chrome)
|
16
|
+
url = "https://www.rakuten-sec.co.jp/ITS/V_ACT_Login.html"
|
17
|
+
driver.get url
|
18
|
+
driver.find_element(id: "form-login-id").send_keys @login[:login_id]
|
19
|
+
driver.find_element(id: "form-login-pass").send_keys @login[:login_pw]
|
20
|
+
driver.find_element(id: "login-btn").click
|
21
|
+
driver
|
22
|
+
end
|
23
|
+
|
24
|
+
def favorite num, codes
|
25
|
+
driver = login
|
26
|
+
sleep 2
|
27
|
+
driver.action.move_to(driver.find_element(id: "gmenu_domestic_stock")).perform
|
28
|
+
sleep 2
|
29
|
+
driver.find_element(id: "gmenu_domestic_stock").click
|
30
|
+
sleep 2
|
31
|
+
driver.find_element(link_text: "お気に入り銘柄").click
|
32
|
+
sleep 2
|
33
|
+
driver.find_element(link_text: num).click
|
34
|
+
sleep 2
|
35
|
+
driver.find_element(name: "editAnchor").click
|
36
|
+
sleep 2
|
37
|
+
driver.find_element(name: "addAnchor").click
|
38
|
+
sleep 1
|
39
|
+
driver.switch_to.frame driver.find_element(:id, "TB_iframeContent")
|
40
|
+
codes.each do |code|
|
41
|
+
result = click_favorite driver, code
|
42
|
+
next if result == "already exist"
|
43
|
+
end
|
44
|
+
driver.find_element(id: "prc_save_button1").click
|
45
|
+
{ status: "success"}
|
46
|
+
end
|
47
|
+
|
48
|
+
def click_favorite driver, code
|
49
|
+
sleep 2
|
50
|
+
driver.find_element(name: "dscrCdNm").clear
|
51
|
+
driver.find_element(name: "dscrCdNm").send_keys code
|
52
|
+
driver.find_element(name: "dscrCdNm").send_keys(:enter)
|
53
|
+
sleep 2
|
54
|
+
rows = driver.find_elements(xpath: "//tr")
|
55
|
+
value = ""
|
56
|
+
num = 0
|
57
|
+
rows[3..rows.size-1].each_with_index do |f, i|
|
58
|
+
cells = f.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
|
59
|
+
value = i if cells[1] == code and cells[3] == "東証"
|
60
|
+
num += 1
|
61
|
+
end
|
62
|
+
while value == ""
|
63
|
+
driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/table/tbody/tr/td/form/ul/li[2]/a").click
|
64
|
+
rows = driver.find_elements(xpath: "//tr")
|
65
|
+
rows[3..rows.size-1].each_with_index do |f, i|
|
66
|
+
cells = f.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
|
67
|
+
value = i + num - 1 if cells[1] == code and cells[3] == "東証"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
driver.find_element(xpath: "//*[@id='#{value}']").click
|
71
|
+
sleep 2
|
72
|
+
driver.find_element(xpath: "//*[@id='str-main-inner']/table/tbody/tr/td/table/tbody/tr/td/form/div[3]/ul/li/a/img").click
|
73
|
+
begin
|
74
|
+
return "already exist" if driver.find_element(xpath: "//*[@id='err_msg']").text.include? "すでに登録済みの銘柄が含まれています。"
|
75
|
+
rescue
|
76
|
+
end
|
77
|
+
driver
|
78
|
+
end
|
79
|
+
|
14
80
|
def todays_order
|
15
81
|
driver = get_selenium_driver(:chrome)
|
16
82
|
wait = Selenium::WebDriver::Wait.new(timeout: 100)
|
@@ -35,7 +101,7 @@ module RakutenSecuritiesScraper
|
|
35
101
|
sleep 2
|
36
102
|
tables = driver.find_elements(xpath: "//tr")
|
37
103
|
page_num = driver.find_element(class_name: "mtext").text.scan(/(.+)件中/)[0][0].to_i
|
38
|
-
row_nums = (21..(21 + (page_num * 3) -1)).to_a
|
104
|
+
row_nums = (21..(21 + (page_num * 3) - 1)).to_a
|
39
105
|
records = []
|
40
106
|
row_nums.each_slice(3).to_a.map do |col_num|
|
41
107
|
detail = {}
|
@@ -128,7 +194,7 @@ module RakutenSecuritiesScraper
|
|
128
194
|
def trade_table_data driver, page_num
|
129
195
|
run_times = page_num.divmod(20)
|
130
196
|
trade_records = []
|
131
|
-
(1..run_times[0]-1).each do |f|
|
197
|
+
(1..run_times[0] - 1).each do |f|
|
132
198
|
rows = driver.find_elements(xpath: "//tr")
|
133
199
|
rows[10..29].map do |row|
|
134
200
|
cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
|
@@ -163,7 +229,7 @@ module RakutenSecuritiesScraper
|
|
163
229
|
return trade_records
|
164
230
|
end
|
165
231
|
rows = driver.find_elements(xpath: "//tr")
|
166
|
-
rows[10.."1#{run_times[1]}".to_i-1].map do |row|
|
232
|
+
rows[10.."1#{run_times[1]}".to_i - 1].map do |row|
|
167
233
|
cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
|
168
234
|
trade_records << {
|
169
235
|
bit_date: cells[0].split("\n")[0],
|
@@ -23,4 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.bindir = "exe"
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_runtime_dependency "selenium-webdriver", "~> 3.142.7"
|
26
30
|
end
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rakuten_securities_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FUMI-POPPIN
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: selenium-webdriver
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.142.7
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.142.7
|
13
69
|
description: This gem is providing scraper methods for everyone to be able to make
|
14
70
|
stock trading applications without writing scraper codes.
|
15
71
|
email:
|