Quora is a more well-known community question and answer site, for the current more popular CQA problem, through the Quora provided by the search tools to find similar problems and then extract answers.
In fact, Quora's search is roughly based on keyword matching.
String s=httprequest.sendget ("Https://www.quora.com/search", "q=have%20you%20ever%20done%20the%20nofap% 20Challenge? ");
Document doc = Jsoup.parse (s);
list<string> Answer_url = new arraylist<string> ();
Elements Ctag = Doc.select ("Div.pagedlist_item");
System.out.println (s);
for (element Question:ctag) {
element href = question.select ("A.question_link").
if (href!= null) {
System.out.println ("www.quora.com" + href.attr ("href"));
Answer_url.add ("https://www.quora.com" + href.attr ("href"));
}
for (String url:answer_url) {
//url = "http://www.quora.com/ What-is-the-craziest-thing-you-have-ever-said-or-done-at-an-interview-and-still-got-the-job ";
String page = httprequest.sendget (URL, "");
SYSTEM.OUT.PRINTLN (page);
Solveanswerpage sol = new Solveanswerpage ();
list<string> iRes = sol.solve (page);
for (String tem:ires) {
// System.out.println (TEM);
}
//break;
}
System.out.println ("Done");
public class Solveanswerpage {public
list<string> solve (String s) {
list<string> res = new ArrayList <String> ();
Document doc = Jsoup.parse (s);
Elements answers = Doc.select ("Div.pagedlist_item");
System.out.println (Answers.size ());
for (Element answer:answers) {
res.add (Answer.text ());
System.out.println (Answer.text ());
}
return res;
}
The main thing is to use the HttpRequest class to achieve the similar problem of a given problem crawl, mainly divided into two steps:
1. First of all, through the problem of a similar problem to search the page, get the list of the top questions URL link
2. According to the first step of the URL list, grab the corresponding problem page answer, and return to crawl results