|
1 | | - |
2 | 1 | class IntermineScraper < Tess::Scrapers::Scraper |
3 | | - |
4 | 2 | def self.config |
5 | 3 | { |
6 | | - name: 'Intermine Scraper', |
7 | | - index_page: 'http://intermine.org/tutorials/' |
| 4 | + name: "Intermine Scraper", |
| 5 | + index_page: "http://intermine.org/tutorials/", |
8 | 6 | } |
9 | 7 | end |
10 | 8 |
|
11 | 9 | def scrape |
12 | | - cp = add_content_provider(Tess::API::ContentProvider.new( |
13 | | - title: "InterMine", #name |
14 | | - url: "http://intermine.org", #url |
15 | | - image_url: "https://cdn.rawgit.com/intermine/design-materials/ff1ec6bf/logos/intermine/intermine-300x37.png", #logo |
16 | | - description: "nterMine integrates biological data sources, making it easy to query and analyse data.", #description |
17 | | - content_provider_type: :project, |
18 | | - node_name: :'UK' |
19 | | - )) |
| 10 | + cp = add_content_provider(Tess::API::ContentProvider.new( |
| 11 | + title: "InterMine", #name |
| 12 | + url: "http://intermine.org", #url |
| 13 | + image_url: "https://cdn.rawgit.com/intermine/design-materials/ff1ec6bf/logos/intermine/intermine-300x37.png", #logo |
| 14 | + description: "nterMine integrates biological data sources, making it easy to query and analyse data.", #description |
| 15 | + content_provider_type: :project, |
| 16 | + node_name: :'UK', |
| 17 | + )) |
| 18 | + |
| 19 | + #page = Nokogiri::HTML.parse(open(config[:index_page]).read) |
| 20 | + index = "http://intermine.org/tutorials/" |
| 21 | + page = Nokogiri::HTML.parse(open(index).read) |
| 22 | + tutorials = page.xpath("/html/body/main/ul/li") |
20 | 23 |
|
21 | | - #page = Nokogiri::HTML.parse(open(config[:index_page]).read) |
22 | | - index = 'http://intermine.org/tutorials/' |
23 | | - page = Nokogiri::HTML.parse(open(index).read) |
24 | | - tutorials = page.xpath('/html/body/main/ul/li') |
25 | | - |
26 | | - tutorials.each do |tutorial| |
27 | | - url = tutorial.children.first.attributes['href'].value |
28 | | - title = tutorial.text.split('-').first |
29 | | - description = tutorial.text |
30 | | - event = Tess::API::Material.new( |
31 | | - title: title, |
32 | | - url: url, |
33 | | - content_provider: cp, |
34 | | - short_description: description, |
35 | | - keywords: title.split(' ').first |
36 | | - ) |
37 | | - add_material(event) |
38 | | - end |
39 | | - end |
| 24 | + tutorials.each do |tutorial| |
| 25 | + if !tutorial.children.first.attributes["href"].nil? |
| 26 | + url = tutorial.children.first.attributes["href"].value |
| 27 | + title = tutorial.text.split("-").first |
| 28 | + description = tutorial.text |
| 29 | + event = Tess::API::Material.new( |
| 30 | + title: title, |
| 31 | + url: url, |
| 32 | + content_provider: cp, |
| 33 | + short_description: description, |
| 34 | + keywords: title.split(" ").first, |
| 35 | + ) |
| 36 | + add_material(event) |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + #page = Nokogiri::HTML.parse(open(config[:index_page]).read) |
| 41 | + index = "http://intermine.org/training-workshops/" |
| 42 | + page = Nokogiri::HTML.parse(open(index).read) |
| 43 | + tutorials = page.xpath("/html/body/div/section/ul/li/a") |
| 44 | + tutorials.each do |tutorial| |
| 45 | + if !tutorial.attributes["href"].nil? |
| 46 | + url = tutorial.attributes["href"].value |
| 47 | + # Complete relative URL paths |
| 48 | + if !url.include? "http" |
| 49 | + url = index + url |
| 50 | + end |
| 51 | + title = tutorial.children.text |
| 52 | + description = title |
| 53 | + event = Tess::API::Material.new( |
| 54 | + title: title, |
| 55 | + url: url, |
| 56 | + content_provider: cp, |
| 57 | + short_description: description, |
| 58 | + keywords: title.split(" ").first, |
| 59 | + ) |
| 60 | + add_material(event) |
| 61 | + end |
| 62 | + end |
| 63 | + end |
40 | 64 | end |
0 commit comments