Skip to content

Instantly share code, notes, and snippets.

@forresty
Created October 11, 2011 03:25
Show Gist options
  • Save forresty/1277198 to your computer and use it in GitHub Desktop.
Save forresty/1277198 to your computer and use it in GitHub Desktop.
A browser script to automatically parse all lixian.vip.xunlei.com file names and URLs
#!/usr/bin/env ruby
require "yaml"
# make sure you have dump cookies to xunlei-cookies.txt
YAML.load_file("all_files.yml").each do |file|
cmd = "wget --load-cookies=xunlei-cookies.txt '#{file[:url]}' -c -O '#{file[:name]}'"
system(cmd)
end
#!/usr/bin/env ruby
require 'watir-webdriver'
require "yaml"
browser = Watir::Browser.new :firefox
browser.goto "http://lixian.vip.xunlei.com"
browser.text_field(:id => "u").when_present.set("TODO: SET_YOUR_USERNAME_HERE")
browser.text_field(:id => "p_show").when_present.set("TODO: SET_YOUR_PASSWORD_HERE")
browser.button(:id => "button_submit4reg").when_present.click
task_list = browser.div(:id => "rowbox_list")
task_list.wait_until_present
@all_files = []
task_list.divs(:class => "rw_list").each do |task_div|
task_div.wait_until_present
if task_div.em(:class => "loadnum").text == "100%"
task_div.click
task_div.a(:class => "rwbtn ic_down").wait_until_present
if task_div.a(:class => "rwbtn ic_play").present?
# normal task
normal_task_a = task_div.span(:class => "namelink").as.first
normal_task_input = task_div.input(:id => "dl_url" + task_div.id.gsub(/\D+/, ""))
@all_files << { :name => normal_task_a.text, :url => normal_task_input.value }
else
# bt task
task_div.a(:class => "rwbtn ic_open").when_present.click
folder_list = browser.div(:id => "rwbox_bt_list")
folder_list.wait_until_present
folder_list.as(:name => "bturls").each do |a|
@all_files << { :name => a.text, :url => a.href }
end
# go back
back_div = browser.div(:id => "view_bt_list_nav")
back_div.wait_until_present
back_div.lis(:class => "main_link main_linksub").first.a(:class => "btn_m").click
end
else
# the task is still downloading
end
end
browser.close
# p @all_files
File.open("all_files.yml", "w") { |f| f.write(@all_files.to_yaml) }
puts "Successfully saved file names and URLs to all_files.yml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment