[語法] 想請問各位大神這個code是不是有問題

看板java作者 (任我行)時間3年前 (2020/11/07 20:52), 編輯推噓4(408)
留言12則, 11人參與, 3年前最新討論串1/1
各位好,前幾天用下列程式碼爬了這個粉專2017-2019的資料,但電腦一直轉不確定是什麼因素,可以請各位大神幫我看看是不是有什麼問題,感激不盡! https://www.facebook.com/equallovetw/ ————————————————————— var auto_slide = true; let data = []; function load_list() { if (!auto_slide) { return } window.scroll(0, window.pageYOffset + 500); showDetailArticle(); removeExtraArticle(); setTimeout(function () { load_list(); }, 350); } function removeExtraArticle() { var rows = document.querySelectorAll(':not(li) > div[class="_4-u2 _4-u8"]'); if (rows.length < 40) { return; } for (let s=0; s<= rows.length; s++) { if (s >= 20) { break; } if (rows[s] && rows[s].querySelector('abbr[data-utime]')) { if (rows[s].querySelector('abbr[data-utime]').getAttribute('title').contains('2020')) { rows[s].remove(); } } } } function showDetailArticle() { var rows = document.querySelectorAll(':not(li) > div[class="_4-u2 _4-u8"]'); for (let s=0; s<= rows.length; s++) { if (rows[s] && rows[s].querySelector('abbr[data-utime]')) { if (rows[s].querySelector('abbr[data-utime]').getAttribute('title').contains('2016')) { auto_slide = false; return; } if ( rows[s].querySelector('abbr[data-utime]').getAttribute('title').contains('2019') || rows[s].querySelector('abbr[data-utime]').getAttribute('title').contains('2018') || rows[s].querySelector('abbr[data-utime]').getAttribute('title').contains('2017') ) { if (rows[s].querySelector('.see_more_link_inner')) { rows[s].querySelector('.see_more_link_inner').click(); } setTimeout(function () { this.target.classList.add('more-clicked'); }.bind({ target: rows[s], }), 500); rows[s].classList.add('more-clicking'); } } } } function download(data) { const filename = 'output.tsv'; const blob = new Blob([data], {type: 'text/json'}); const e = document.createEvent('MouseEvents'); const a = document.createElement('a'); a.download = filename; a.href = window.URL.createObjectURL(blob); a.dataset.downloadurl = ['text/json', a.download, a.href].join(':'); e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); a.dispatchEvent(e); } function captureArticle() { console.log('zzzzzzz'); var rows = document.querySelectorAll(':not(li) > div._4-u2._4-u8.more-clicked'); for (let s=0; s< rows.length; s++) { if (rows[s] && rows[s].querySelector('[data-testid="post_message"]') && rows[s].querySelector('abbr[data-utime]')) { // console.log('----------------------------------------------------------------'); // console.log('----------------------------------------------------------------'); // console.log(rows[s].querySelector('abbr[data-utime]').getAttribute('title'), rows[s].querySelector('[data-testid="post_message"]').innerText); /* data.push({ date: rows[s].querySelector('abbr[data-utime]').getAttribute('title'), text: rows[s].querySelector('[data-testid="post_message"]').innerText, liked: rows[s].querySelector('span._81hb').textContent, shared: rows[s].querySelector("a[class='_3rwx _42ft']").text.split(' ')[0], }); */ let liked = rows[s].querySelector('span._81hb') || '0'; if (liked !== '0') { liked = liked.textContent; } let shared = rows[s].querySelector("a[class='_3rwx _42ft']") || '0'; if (shared !== '0') { shared = shared.text.split(' ')[0]; // a._3rwx _42ft <a>text</a> } data.push([ rows[s].querySelector('abbr[data-utime]').getAttribute('title'), rows[s].querySelector('[data-testid="post_message"]').innerText, liked, shared, ]); // console.log(data[data.length-1]); } rows[s].remove(); } if (!auto_slide && rows.length === 0) { auto_slide = false; console.log("Scrape End"); let str = 'Date\tText\tLiked\tShared'; for (const post in data) { str += ('\n'+data[post].map(d => `"${d.replaceAll('"', '""')}"`).join('\t')); } console.log(str); download(str); return; } setTimeout(function () { captureArticle(); }, 5000); } load_list(); captureArticle(); ----- Sent from JPTT on my iPhone -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.10.4.19 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/java/M.1604753578.A.35E.html

11/07 22:26, 3年前 , 1F
狗和熱狗的問題吧
11/07 22:26, 1F

11/08 09:36, 3年前 , 2F
這問題大惹
11/08 09:36, 2F

11/08 11:41, 3年前 , 3F
可以請問一下是什麼問題嘛?
11/08 11:41, 3F

11/08 11:41, 3年前 , 4F
因為我抓另外一個粉專是可以的,但這一個抓不太下來
11/08 11:41, 4F

11/08 12:27, 3年前 , 5F
這是JavaScript 然後你來Java版問 看出問題了吧
11/08 12:27, 5F

11/09 17:26, 3年前 , 6F
樓上XD
11/09 17:26, 6F

11/11 12:58, 3年前 , 7F
這讓我想到這版好像還沒有人問過Rhinos的樣子
11/11 12:58, 7F

11/11 14:16, 3年前 , 8F
恩 狗和熱狗 滿中肯的
11/11 14:16, 8F

11/12 09:29, 3年前 , 9F
XD
11/12 09:29, 9F

11/12 14:46, 3年前 , 10F
狗也是可以是一種熱狗,不管是直接加熱或者料理後加熱(誤)
11/12 14:46, 10F

11/12 19:44, 3年前 , 11F
然後樓上會被動保人士關切。
11/12 19:44, 11F

11/17 21:04, 3年前 , 12F
看到let還往上滑,以為走錯版
11/17 21:04, 12F
文章代碼(AID): #1VffYgDU (java)
文章代碼(AID): #1VffYgDU (java)