busgogo 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +3 -4
- data/lib/busgogo.rb +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 897decea32acccee8d20ae98fb8f1bd262f248b6
|
4
|
+
data.tar.gz: 8afa4ddec43df7725c81bae6d13c55142206787a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7161db07232c565d6937e2d1dd590d74cb77c1cdd2ae93b6b987db4f44cdd35d83b1dfd0c48acea5aaeeeb0952abc2369c8e06d4b910f099df6a6fb8cb19ac10
|
7
|
+
data.tar.gz: cbf305c668dbb830e2fcdac1f8dd034d107ff2bdd005204aec8a81e79bc0cf88d4b40962fd8f54f1c55530d2b8147f4797c5f1945099384f2b74373ef9fdf1b6
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: busgogo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mavis Cheng (Cheng SyunWei), Yen Wei ,Wu ChiaChun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,8 +43,7 @@ email: wei.yen.0718@gmail.com
|
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
|
-
files:
|
47
|
-
- lib/busgogo.rb
|
46
|
+
files: []
|
48
47
|
homepage: http://rubygems.org/gems/busgogo
|
49
48
|
licenses: []
|
50
49
|
metadata: {}
|
data/lib/busgogo.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
require 'mechanize'
|
4
|
-
# Class that can be used to grab data from website(http://www.hcbus.com.tw/)
|
5
|
-
class WebScraper
|
6
|
-
# @data stores information
|
7
|
-
attr_accessor :data
|
8
|
-
attr_accessor :station
|
9
|
-
attr_accessor :page
|
10
|
-
attr_accessor :output
|
11
|
-
attr_accessor :url
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@data = data
|
15
|
-
@station = station
|
16
|
-
@page = page
|
17
|
-
@output = output
|
18
|
-
@url = url
|
19
|
-
end
|
20
|
-
|
21
|
-
def getwebstructure(website)
|
22
|
-
web_data = open(website)
|
23
|
-
@data = Nokogiri.HTML(web_data)
|
24
|
-
end
|
25
|
-
|
26
|
-
def file_output
|
27
|
-
selectstation
|
28
|
-
File.write('Output.txt', @output)
|
29
|
-
puts "\n\n\nPlease check data in Output.txt file"
|
30
|
-
end
|
31
|
-
|
32
|
-
def busstation
|
33
|
-
@url = 'http://www.hcbus.com.tw/big5/service.asp'
|
34
|
-
num, @station = 1, {}
|
35
|
-
getwebstructure(url)
|
36
|
-
@data.css("select[name='jumpMenu'] option").each do |x|
|
37
|
-
@station[num] = x.text
|
38
|
-
num += 1
|
39
|
-
end
|
40
|
-
@station
|
41
|
-
end
|
42
|
-
|
43
|
-
def selectdropdown(url, num)
|
44
|
-
tmpkey = [], tmpvalue = []
|
45
|
-
agent = Mechanize.new
|
46
|
-
form = agent.get(url).forms.first
|
47
|
-
form.field_with(name: 'jumpMenu').options[num].click
|
48
|
-
@page = form.submit
|
49
|
-
content = @page.parser.xpath("//table/tr/td[@class='map-style']")
|
50
|
-
content2 = @page.parser.xpath("//table/tr/td[@class='map-style'][1]")
|
51
|
-
content2.each { |b| tmpkey << b.text.strip }
|
52
|
-
content.each { |c| tmpvalue << c.text.strip }
|
53
|
-
filehash(tmpvalue, tmpkey)
|
54
|
-
end
|
55
|
-
|
56
|
-
def filehash(value, key)
|
57
|
-
value.each do |v|
|
58
|
-
key.each do |c|
|
59
|
-
@output << '**************************************' if v == c
|
60
|
-
end
|
61
|
-
@output << v
|
62
|
-
end
|
63
|
-
@output << '**************************************'
|
64
|
-
end
|
65
|
-
|
66
|
-
def tmp_selectstation
|
67
|
-
num, @station, @output = 1, {}, []
|
68
|
-
getwebstructure(url)
|
69
|
-
@data.css("select[name='jumpMenu'] option").each do |x|
|
70
|
-
@station[num] = x.text
|
71
|
-
num += 1
|
72
|
-
end
|
73
|
-
(0...9).each do |i|
|
74
|
-
selectdropdown(@url, i)
|
75
|
-
end
|
76
|
-
@output
|
77
|
-
end
|
78
|
-
end
|