Last active
August 29, 2015 14:06
-
-
Save b0n/c438dd80b597dcd1254d to your computer and use it in GitHub Desktop.
Select plugin name and version from wp page or plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'open-uri' | |
require 'nokogiri' | |
url = "http://test.localhost/abc.plugin.html" | |
charset = nil | |
html = open(url) do |f| | |
charset = f.charset | |
f.read | |
end | |
doc = Nokogiri::HTML.parse(html, nil, charset) | |
plugins = Array.new() | |
doc.xpath('//tr[@class="active"]').each do |node| | |
name = node.xpath('td[@class="plugin-title"]/strong/text()').to_s | |
ver = node.xpath('td/div[@class="active second plugin-version-author-uri"]/text()') | |
/^[^ ]+ (.*) \| .*$/.match(ver[0].to_s) | |
ver = $1 | |
plugins.push({'name'=> name, 'ver'=> ver}) | |
end | |
require 'json' | |
puts JSON.generate(plugins) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment