Skip to content

Instantly share code, notes, and snippets.

Created March 22, 2017 04:32
What would you like to do?
웹 페이지의 특정 정보를 추출하여 json 형태로 만들기
* This is a JavaScript Scratchpad.
* Enter some JavaScript, then Right Click or choose from the Execute Menu:
* 1. Run to evaluate the selected text (Cmd-R),
* 2. Inspect to bring up an Object Inspector on the result (Cmd-I), or,
* 3. Display to insert the result in a comment after the selection. (Cmd-L)
// run at
<span class="number">2</span>
<a href=";lo=z45">
<img src="" alt="" width="50" height="40">
IT人은 왜 늘 약자 입장에 처하게 될까
var lis = document.querySelectorAll('.news_9 ol>li');
var result = [];
lis.forEach(function (li) {
var number = li.querySelector('div > span.number').innerText;
var a = li.querySelector('div > a[href]');
var href = a.getAttribute('href');
var img = a.querySelector('img[src]').getAttribute('src');
var span = a.querySelector('span').innerText.trim();
'number': number,
'href': href,
'img': img,
'span': span
[{"number":"1","href":"","img":"","span":"\"IT 개발자?…부품과 다를 바 없어요\""},{"number":"2","href":"","img":"","span":"IT人은 왜 늘 약자 입장에 처하게 될까"},{"number":"3","href":"","img":"","span":"\"4차산업혁명?…IT 中企는 죽을 맛이죠\""},{"number":"4","href":"","img":"","span":"삼성 갤럭시S8 공개 D-9…기대감 '최고조'"},{"number":"5","href":"","img":"","span":"일주일 만에 '랩하는 AI' 만든 美 10대 소년"},{"number":"6","href":"","img":"","span":"“삼성 갤럭시S8, 세 종류 색상 출시”"},{"number":"7","href":"","img":"","span":"진짜로 혁신하려거든 IT에 부탁하라"},{"number":"8","href":"","img":"","span":"갤S8에 '빅스비' 버튼…\"인터페이스 혁신\""},{"number":"9","href":"","img":"","span":"전기차 15분 충전…'포르쉐 선언' 가능할까"},{"number":"10","href":"","img":"","span":"현대차, '2017 아반떼' 출시...1천570만원부터"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment