-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrap_data.rb
More file actions
35 lines (29 loc) · 763 Bytes
/
scrap_data.rb
File metadata and controls
35 lines (29 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "mechanize"
require "nokogiri"
require "awesome_print"
url = ARGV[0]
fp = File.new("wikilinks.txt", "w")
agent = Mechanize.new { |agent| agent.user_agent_alias = "Mac Safari" }
html = agent.get(url).body
html_doc = Nokogiri::HTML(html)
list = html_doc.xpath("//ul[@class='list_horiz']")
h={}
list.each { |i|
name = i.xpath('//a').text
url = i.xpath('//a/@href').text
# title = i.xpath("//a[@href]")
# title.map do |x|
# [
# x.text,x['href']
# ]
# ap x
# end
ap name.gsub("\n\t\t\t\t\t\t"," ")
# h[title.text.strip] = title['href']
# puts h[title.text.strip] # fp.write(i.text + "\n")
# s = title.gsub("/t/t/t/t/t","")
# s = s.gsub("</section>","")
# s = s.gsub("<br/><br/>","\n")
# puts title.strip
}
# ap h