Ruby中使用mechanize批量下载校内网相册照片

2019-09-25 09:45:56丽君

              photo.save
            end
          end
      end
      puts Iconv.conv("gb2312","utf-8","相册下载完毕.....")
    else
      puts Iconv.conv("gb2312","utf-8","相册内没有照片哟~")
    end
  end

  private

  def parse_album_uri(uri)
    uri = uri.chomp("#thumb")
    uri = uri.split("?")
    if uri.length > 1 and uri[1].include?("owner")
      uri = uri[1].split("&")
      user_id = uri[0].split("=")[1]
      album_id = uri[1].split("=")[1]
    else
      uri = uri[0].split("/")
      album_id = uri[4]
      user_id = uri[5].split("-")[1]
    end
    return user_id,album_id
  end
end

print Iconv.conv("gb2312","utf-8","用户名:")
username = gets.chomp()
print Iconv.conv("gb2312","utf-8","密码:")
password = gets.chomp()
renren = Renren.new(username,password)
loop do
  print Iconv.conv("gb2312","utf-8","粘贴相册地址:")
  uri = gets.chomp()
  renren.fetch_other_photo(uri, username)
  print Iconv.conv("gb2312","utf-8","按0退出程序,按其它键继续下载其它相册:")
  break if gets.chomp() == "0"
end