這篇文章主要介紹“怎么用Java打印出貼吧某用戶發(fā)表過的所有帖子”,在日常操作中,相信很多人在怎么用Java打印出貼吧某用戶發(fā)表過的所有帖子問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”怎么用Java打印出貼吧某用戶發(fā)表過的所有帖子”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè)|成都企業(yè)網(wǎng)站維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋混凝土攪拌機(jī)等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身制作品質(zhì)網(wǎng)站。
代碼如下:
<html>
<meta charset="UTF-8"/>
<style>
a {
color: green;
font-family: arial;
font-weight: bold
}
</style>
<body>
<div id="container"></div>
</body>
<script src="jquery1.7.1.js">
</script>
<script>
/*
這個(gè)警告的意思是說:請(qǐng)求的資源可能會(huì)被(擴(kuò)展/或其他什么機(jī)制)屏蔽掉。
之所以會(huì)出現(xiàn)這個(gè)警告,是因?yàn)槿カ@取該資源的請(qǐng)求其實(shí)并(還)沒有真的發(fā)生,所以 Header 里顯示的是偽信息,直到服務(wù)器真的有響應(yīng)返回,這里的 Header 信息才會(huì)被更新為真實(shí)的。不過這一切也可能不會(huì)發(fā)生,因?yàn)樵撜?qǐng)求可能會(huì)被屏蔽。比如說 AdBlock 什么的,當(dāng)然了不全是瀏覽器擴(kuò)展,具體情況具體分析了。
對(duì)了,別忘了用 chrome://net-internals 來幫助你查找被屏蔽的請(qǐng)求以及可能的原因。
*/
var PREFIX = "http://tieba.baidu.com";
var START = "http://tieba.baidu.com/i/i/my_tie";
//var START = "http://www.baidu.com";
var POST = {};
var TOTAL = 0;
var SORTED = [];
function getTotalCount(collection){
var count = 0;
for( bar in collection){
if( !collection.hasOwnProperty(bar))
continue;
var postList = collection[bar];
count += postList.length;
}
return count;
}
function shouldEnd(previousCount) {
TOTAL = getTotalCount(POST);
console.log("pre: " + previousCount + " total: " + TOTAL);
return ( previousCount == TOTAL );
}
function main() {
var html = getPostByAJAX(START);
handleLiChildren(html);
var page = 2;
while(1){
var prevCount = getTotalCount(POST);
var task = START + "?&pn=" + page;
var html = getPostByAJAX(task);
handleLiChildren(html);
page++;
/*
if( page >=2 )
break;*/
if( shouldEnd(prevCount) )
break;
}
sort();
generate();
}
function handleLiChildren(resultString){
var htmlDom = $(resultString);
var liChildren = $("li", htmlDom);
$.each( liChildren, function(i, value) {
// if( value.className.indexOf("nav_item") != -1 )
if( value.className)
return true;
if( value.innerText == "我回復(fù)的" || value.innerText == "我的精品")
return true;
var detail = parseDetail(value);
insertPost(detail);
});
}
/*
<ul>
<li>
<cite>2016</cite>
<a href="/f?kw=%E5%A4%A7%E9%82%91" >尿素氮</a>
</li>
<li>
<cite>2015</cite>
<a href="/f?kw=%E5%A4%A7%E9%82%91" >尿素氮2</a>
</li>
</ul>
*/
function getpostSource(post) {
var source = "<li><cite>";
source += post.date + "/<cite>";
source += '<a href="' + post.url + '">' + post.postTitle + "</a></li>";
return source;
}
function getBarPostsSource(barName, posts) {
var source = '<h2>' + barName + ': ' + posts.length + '個(gè)</h2>';
source += "<ul>";
for( var i = 0; i < posts.length; i++){
var post = posts[i];
source += getpostSource(post);
}
source += "</ul>";
return source;
}
function sortNumber(a,b){
return b.size - a.size;
}
function sort() {
for( barName in POST) {
if( !POST.hasOwnProperty(barName))
continue;
var post = {
name: barName,
size: POST[barName].length
};
SORTED.push(post);
}
SORTED.sort(sortNumber);
}
function generate(){
var div = document.getElementById("container");
var source = "總共帖子: " + TOTAL + "個(gè)";
for( var i = 0; i < SORTED.length; i++){
var posts = POST[SORTED[i].name];
source += getBarPostsSource(SORTED[i].name, posts);
}
div.innerHTML = source;
}
$(function(){
main();
});
function getPostByAJAX(requestURL){
var html = $.ajax({
url: requestURL,
xhrFields: {
// The 'xhrFields' property sets additional fields on the XMLHttpRequest.
// This can be used to set the 'withCredentials' property.
// Set the value to 'true' if you'd like to pass cookies to the server.
// If this is enabled, your server must respond with the header
// 'Access-Control-Allow-Credentials: true'.
withCredentials: true
},
async: false}).responseText;
debugger;
return html;
}
/*
function getPostByAJAX(requestURL){
var settings = {
type: "GET",
crossOrigin: true,
url:requestURL,
error: function(XHR,textStatus,errorThrown) {
alert ("XHR="+XHR+"\ntextStatus="+textStatus+"\nerrorThrown=" + errorThrown);
},
success: function(data,textStatus) {
debugger;
},
headers: {
"Access-Control-Allow-Origin":"http://tieba.baidu.com",
"Access-Control-Allow-Headers":"X-Requested-With"
}
};
$.ajax(settings);
}
*/
/*
function getPostByAJAX(requestURL){
var html = $.ajax({
url: requestURL,
dataType:"jsonp",
xhrFields: {
// The 'xhrFields' property sets additional fields on the XMLHttpRequest.
// This can be used to set the 'withCredentials' property.
// Set the value to 'true' if you'd like to pass cookies to the server.
// If this is enabled, your server must respond with the header
// 'Access-Control-Allow-Credentials: true'.
withCredentials: true
},
async: false}).responseText;
return html;
}
*/
function insertPost(postDetail){
if( !POST[postDetail.barName]){
POST[postDetail.barName] = [];
}
POST[postDetail.barName].push(postDetail);
}
function parseDetail(liNode) {
var cite = $("cite", liNode);
var date = cite[0].innerHTML; // value1
var tds = $("td", liNode);
var a1 = $("a", tds[0]);
var barName = a1[0].innerHTML; // value2
var a2 = $("a", tds[1]);
var postTitle = a2[0].innerHTML; // value3
var url = PREFIX + a2.attr("href");
return {
date: date,
barName: barName,
postTitle: postTitle,
url: url
}
}
function getTestData(){
return '<!DOCTYPE html><html><body><div class="wrap1"><div class="wrap2"><div ' +
' id="main_wrapper" class="main_wrapper"><div id="main_back_img"><div ' +
' id="main_back_bottom"><div id="container" class="ibody clearfix"><div><div ' +
' id="content"><div class="simple_block_container"><ul><li><cite>2-16</cite>' +
'<div class="wrap_container"><table><tr><td class="nowrap">在<a style="" ' +
' href="/f?kw=%E5%A4%A7%E9%82%91" target="_blank">ANDROID吧</a> 發(fā)貼</td><td class="wrap">' +
'<a href="/p/4356641476?pid=84106363194&cid=0#841063631" class="thread_title" target="_blank">硬盤</a></td>' +
'</tr></table></div><div class="clear"></div></li>' +
'<li></li><li></li></ul></div></div></div></div></div></div></div></div></body></html>';
}
</script>
</html>到此,關(guān)于“怎么用Java打印出貼吧某用戶發(fā)表過的所有帖子”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
網(wǎng)站標(biāo)題:怎么用Java打印出貼吧某用戶發(fā)表過的所有帖子
URL地址:http://chinadenli.net/article8/iighop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、面包屑導(dǎo)航、自適應(yīng)網(wǎng)站、商城網(wǎng)站、定制網(wǎng)站、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)