Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java to print out all the posts posted by a certain user

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use Java to print out all the posts posted by a certain user". In daily operation, I believe that many people have doubts about how to use Java to print out all the posts posted by a certain user. Xiaobian consulted all kinds of materials and sorted out simple and useful methods of operation. I hope it will be helpful to answer the doubts of "how to use Java to print out all the posts posted by a certain user". Next, please follow the editor to study!

The code is as follows:

A {color: green; font-family: arial; font-weight: bold} / * this warning means that the requested resource may be blocked by (extension / or some other mechanism). The reason for this warning is that the request to get the resource did not really happen, so the false information is displayed in Header, and the Header information will not be updated to real until the server does return a response. However, this may not happen because the request may be blocked. For example, AdBlock and so on, of course, not all browser extensions, specific analysis of the specific situation. By the way, don't forget to use chrome://net-internals to help you find blocked requests and possible reasons. * / 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 function getTotalCount 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 = "my reply" | | value.innerText = = "my boutique") return true; var detail = parseDetail (value) InsertPost (detail);});} / * 2016 urea nitrogen 2015 urea nitrogen 2 * / function getpostSource (post) {var source = ""; source + = post.date + "/"; source + =''+ post.postTitle + ""; return source;} function getBarPostsSource (barName, posts) {var source =''+ barName +':'+ posts.length +'' Source + = ""; for (var I = 0; I < posts.length; iTunes +) {var post = posts [I]; source + = getpostSource (post);} source + = ""; return source;} function sortNumber (aQuery 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 posts:" + TOTAL + "one"; for (var I = 0; I < SORTED.length) Function getPostByAJAX +) {var posts = post [SORTED.name]; source + = getBarPostsSource (SORTED.name, posts);} div [XSS _ clean] = 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] [xss_clean]; / / value1 var tds = $("td", liNode) Var A1 = $("a", tds [0]); var barName = A1 [0] [xss_clean]; / / value2 var a2 = $("a", tds [1]); var postTitle = a2 [0] [xss_clean]; / / value3 var url = PREFIX + a2.attr ("href") Return {date: date, barName: barName, postTitle: postTitle, url: url}} function getTestData () {return'2-16' + 'post in ANDROID bar' + 'hard disk' +'+';} at this point, the study on "how to use Java to print and post all the posts posted by a user" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report