So I initially posted a couple days ago requesting assistance for the development of a project which loaded up a webpage and filtered out the desired contents from an ordered list tag.
A user was very helpful in providing me the method on how to use Jsoup to do just that, as shown below.
public static String pharmercyURL = "http://archiveofourown.org/tags/Fareeha%20%22Pharah%22%20Amari*s*Angela%20%22Mercy%22%20Ziegler/works";
Document doc = Jsoup.connect(pharmercyURL).get();
Elements ol = doc.select("ol.work > li");
for (Element li : ol) {
String title = li.select("h4.heading a").first().text();
String author = li.select("h4.heading a[rel=author]").text();
String id = li.attr("id").replaceAll("work_","");
String url = "http://archiveofourown.com/works/" + id;
String summary = li.select("blockquote.summary").text();
String rating = li.select("span.rating").text();
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("ID: " + id);
System.out.println("URL: " + url);
System.out.println("Summary: " + summary);
System.out.println("Rating: " + rating);
}
Though it works fantastically on my home computer, I also wanted to implement it on my discord server, which the rest of which my bot is written in C#.
So luckily, it turns out Csquery has the same general way of going about doing things, using CSS Selectors and whatnot to filter out data. However, I'm having some issues converting the Java code into proper C#, mostly with the fact that I'm using a separate set of libraries, and am not completely sure of the framework behind CsQuery.
Error:
Unable to cast object of type 'CsQuery.Implementation.HTMLLIElement' to type 'CsQuery.CQ'.
-
String searchURL = "http://archiveofourown.org/works/search?utf8=✓&work_search%5Bquery%5D=";
searchURL += fandomParam + "+" + pairingParam + "+" + titleParam + "+" + authorParam + "+" + ratingParam + "+" + otherParam;
CQ dom = CQ.CreateFromUrl(searchURL);
CQ ol = dom.Select("ol.work > li");
Console.WriteLine("sucessfully past CQ initialization");
foreach(CQ li in ol){
String title = li.Select("h4.heading a").First().Text();
await ReplyAsync(title);
break;
}