Last active
November 5, 2020 08:07
-
-
Save ozero/2fd7c1eea4025cfef760858f9340fcc7 to your computer and use it in GitHub Desktop.
Goto Eats Osaka scrape Userscript
This file contains 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
// ==UserScript== | |
// @name Goto Eats Osaka scrape | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description 検索だけでマップがないとかクソすぎへん? | |
// @author You | |
// @match https://goto-eat.weare.osaka-info.jp/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Your code here... | |
let data = {}; | |
data = JSON.parse(localStorage.getItem('goto-scrape')); | |
if(data == null){data = {};} | |
const filter_str = (str) => { | |
str = str + ""; | |
str = zen2han(str); | |
str = str.split(" ").join(" "); | |
str = str.replace(/\r?\n/g," "); | |
str = str.replace(/\t/," "); | |
str = str.replace(/([0-9]+\-[0-9]+)([^\x01-\x7E\xA1-\xDF])/, "$1 $2"); | |
str = str.replace(/^\s+|\s+$/g,'').replace(/ +/g,' '); | |
return str; | |
} | |
const zen2han = (str) => { | |
str = str + ""; | |
return str.replace(/[A-Za-z0-9]/g, function(s) { | |
return String.fromCharCode(s.charCodeAt(0) - 0xFEE0); | |
}); | |
} | |
const list = $(".search_result_box > ul > li"); | |
list.each((idx,el)=>{ | |
const name = $(el).find(".name").text(); | |
let tags = []; | |
$(el).find(".tag_list li").each((idx,elt)=>{ | |
tags.push($(elt).text()); | |
}); | |
let info = {}; | |
$(el).find("tr").each((idx,eli)=>{ | |
const info_key = $(eli).find("th").text(); | |
const info_val = $(eli).find("td").text().trim().replace(/ +/, " "); | |
info[info_key] = info_val; | |
}); | |
data[name] = { | |
name: name, | |
info: info, | |
tags: tags | |
}; | |
}); | |
// | |
let tsv=""; | |
for(let dk in data){ | |
let datum = data[dk]; | |
const d_name = filter_str(datum.name); | |
const d_info = datum.info; | |
const d_info_tel = filter_str(d_info.TEL); | |
const d_info_addr = filter_str(d_info["住所"]); | |
const d_info_time = filter_str(d_info["営業時間"]); | |
const d_info_na = filter_str(d_info["定休日"]); | |
const d_tag = data[dk].tags.join(", "); | |
tsv += [d_name,d_info_addr,d_tag,d_info_tel,d_info_time,d_info_na].join("\t") + "\n"; | |
} | |
console.log(tsv); | |
// | |
localStorage.setItem('goto-scrape', JSON.stringify(data)); | |
// | |
if($("a.nextpostslink")){ | |
setTimeout(()=>{ | |
let nexthref = $("a.nextpostslink").attr("href"); | |
if(nexthref){ | |
window.location.href = $("a.nextpostslink").attr("href"); | |
} | |
},1000); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment