Skip to content

Instantly share code, notes, and snippets.

@j138
Last active December 21, 2015 08:39
Show Gist options
  • Save j138/6279424 to your computer and use it in GitHub Desktop.
Save j138/6279424 to your computer and use it in GitHub Desktop.
yahoo画像検索結果をajaxで読み込み、正規表現でパースし、Arrayにくっこむ。
// ==UserScript==
// @name test
// @namespace test
// @description test
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
// var user_name = document.hoge_form.user_input.value;
var user_name = '島風';
// Yahoo画像検索用のURLを生成
var image_search_link = 'http://image.search.yahoo.co.jp/search?p='+encodeURI(user_name)+'&aq=-1&oq=&ei=UTF-8';
console.log(image_search_link);
// AJAXでリクエスト取得
xmlhttp = GM_xmlhttpRequest({
method : 'GET',
url : image_search_link,
onload : parse_result,
onerror : null
});
// Yahooの画像検索画面パース用のメソッド
function parse_result(req) {
// var image_list = new Object();
var image_list = new Array();
var re = new RegExp(/target="imagewin"><img.*?src="(.*?)"/gim);
while(match=re.exec(req.responseText)) {
console.log(match);
image_list.push(match[1]);
}
// よしなに
console.log(image_list);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment