set-scraper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/set-scraper.rb +37 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d71cd5ff8a206b681d7e0756ef4931da47c48d9f6a66a46c5c6191ba3a3ea173
4
+ data.tar.gz: adc9687002d54ada34d49c8d2eaddb75dd84c9cf47857aaed5f22a872a590fbb
5
+ SHA512:
6
+ metadata.gz: 2c7f6dba9fe19978fcf88550582cc2c469b62ea16ad1684ba1096af0476aa86c3690de4ddc36dd6579d7dcd465a7e2247f35f94785ad00b5fbaabfc43f6b14b4
7
+ data.tar.gz: 42e1c021805bbbd9a81fd2c30fb5e6ffb53479d56aad46b5231653b76ed76363a5a0a49eee9881ed6683781e229e39b508034e9d7adf9e1f1b385485b4f226a9
@@ -0,0 +1,37 @@
1
+ # Nuttapol Korcharoenrat
2
+ # 6210546404
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ class Scraper
7
+ def self.set
8
+ html = URI.open("https://www.set.or.th/set/commonslookup.do")
9
+ response = Nokogiri::HTML(html)
10
+ description = response.css("div.row[3] div a").each do |each_page|
11
+ each_html = URI.open("https://www.set.or.th#{each_page.attributes["href"].value}")
12
+ response = Nokogiri::HTML(each_html)
13
+ description = response.css("tr").each_with_index do |obj, index|
14
+ next if index == 0
15
+ full_name = obj.css("td[2]").text
16
+ short_name = obj.css("td a").text
17
+ url = "https://www.set.or.th" + obj.css("td a")[0].attributes["href"].value
18
+ url_assert = url.gsub("profile", "highlight")
19
+ assert_html = URI.open(url_assert)
20
+ response_assert = Nokogiri::HTML(assert_html)
21
+ description_assert = response_assert.css("div.table-responsive").css("table[1]").css("tbody").css("tr[2] td")
22
+ assert_list = []
23
+ description_assert.each do |obj|
24
+ if (obj != nil)
25
+ temp = obj.text.strip.gsub(',','').to_f
26
+ if (temp != 0.0)
27
+ assert_list.push(temp)
28
+ end
29
+ end
30
+ end
31
+ assert = assert_list.length == 0 ? "Not found!!" : assert_list[-1].to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
32
+ # puts url_assert
33
+ puts "#{short_name} : #{full_name} : #{assert}"
34
+ end
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: set-scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nuttapol Korcharoenrat 6210546404
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple web scraper to show the value of the last assets for each stock
14
+ in the Thai stock market.
15
+ email: nuttapol.kor@ku.th
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/set-scraper.rb
21
+ homepage: https://rubygems.org/gems/set-scraper
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.1.4
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Scraper!
44
+ test_files: []