Skip to content

Instantly share code, notes, and snippets.

@jiskanulo
Last active July 29, 2019 15:06
Show Gist options
  • Save jiskanulo/364d0bf7b90e07e6917b to your computer and use it in GitHub Desktop.
Save jiskanulo/364d0bf7b90e07e6917b to your computer and use it in GitHub Desktop.
/out
/vendor

scrape-line-stamp

get thumbnail images from LINE STORE.

how to use

$ ruby ./scrape-line-stamp https://store.line.me/stickershop/product/534/ja

require

nokogiri

# frozen_string_literal: true
source "https://rubygems.org"
gem "nokogiri"
GEM
remote: https://rubygems.org/
specs:
mini_portile2 (2.4.0)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
PLATFORMS
ruby
DEPENDENCIES
nokogiri
BUNDLED WITH
1.17.2
#!/usr/bin/env ruby
require "bundler/setup"
require "fileutils"
require "nokogiri"
require "open-uri"
url = ARGV[0]
doc = Nokogiri::HTML(open(url))
title = doc.title
output_dir = "out/#{title}"
FileUtils.mkdir_p(output_dir)
# <span class="mdCMN09Image FnPreview" style="background-image:url(https://stickershop.line-scdn.net/stickershop/v1/sticker/19216656/iPhone/sticker@2x.png;compress=true);"></span>
doc.xpath('//span[@class="mdCMN09Image FnPreview"]').each do |node|
# style="background-image:url(https://stickershop.line-scdn.net/stickershop/v1/sticker/19216656/iPhone/sticker@2x.png;compress=true);"
# https://stickershop.line-scdn.net/stickershop/v1/sticker/19216656/iPhone/sticker@2x.png
sticker_url = "#{node["style"][/url\((.+)\)/, 1]}"
file_name = output_dir + "/" + sticker_url.sub(/^http(s)*:\/\//, "").gsub(/\//, ".").split(";")[0]
open(sticker_url) do |file|
open(file_name, "w+b") do |out|
out.write(file.read)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment