Read YouTube comment feed using Java - java

I am want to read and display top 200 comments on a video on youtube. Basically when I go to the link: http://gdata.youtube.com/feeds/api/videos/EokUNzGJBI8/comments I get all the comments in rss feed form. How do I parse and read all the comments?
Edit: I have tried the same in php and it's quite easy to retrieve. I need to do it in Java and I am new to it.

You can take the following steps in code:
Load that API in Java - make the call by Downloading the Contents of that Page
Parse the XML using a Java XML Parser
Loop through the comments and do what you will.

Related

Retrieve just the intro text in Wikipedia

How can I retrieve just the intro text (those few lines at the beginning of each article), using java?
I've seen a question like this here, the problem is that the code was in PHP and I need it in java so I can implement it to my android app...
I've tried to search all GitHub for some easy libraries that could help me get what I want and I got no success.
I've also seen that this link: https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=Stack%20Overflow shows information about whatever I want to search. I just can't retrieve the data because, as I said, in that question, the code posted was in PHP
check this https://www.mediawiki.org/api/rest_v1/#!/Page_content/get_page_summary_title
Api for accessing content is here , rest you can normally parse the data.
hope this helps.

Read HTML page, after javascript (java)

in my project I need to read some web pages. Usually it is pretty easy: I read the source code using java classes, parse the output and save interesting data.
But sometimes it is harder; for example reading Google pages. I think it is because of javascript. Do you know to get the real web page code, I mean without javascript? For example if I analyse the page using the Firebug extension of Firefox I read exactly what I need: javascript is correctly replaced by its results. Any idea to do it using Java?
Thanks in advance

Java BlackBerry - How to call a php script properly with GET method?

Hey guys what's up? I'm making a very simple game for BlackBerry Curve 8520, and i need to get the ranking from the server. In order to get this data, the web programmers gave me php files that gets the data from the database and returns it as a dynamic xml file.
My question is:
How can i load that php file using java code? how can i pass a get parameter to that request?
how can i parse the xml retrieved from the php script?
Thanks in advance!
Francisco
You really have two problems here, and I think you should attempt to address them separately.
Problem 1 is getting the data from the Server
Problem 2 is parsing the data you get from the Server.
Both these problems have been covered extensively on this and other forums previously, so I suggest that you search here and elsewhere. Here are a few links from SO:
blackberry HttpConnection.GET
Parse XML file on BlackBerry
In addition, I recommend you review the documentation provided on the official BB site:
http://developer.blackberry.com/bbos/java/
including the following:
http://developer.blackberry.com/bbos/java/documentation/intro_networking_1984362_11.html
As you will see, the BB offers a number of methods of doing communication, in your case I would recommend the ConnectionFactory API:
http://developer.blackberry.com/bbos/java/documentation/network_api_1984363_11.html
And here is something on parsing XML:
http://supportforums.blackberry.com/t5/Java-Development/Use-the-XML-Parser/ta-p/445210
This should be enough to get you going. Please come back with specific questions if you have issues with any of this.

Accessing the same file

I have a situation where in I write to a text file programmatically using java and simultaneously I read from the same file using jQuery.
The problem I face is jQuery is unable to find the updated content whenever a content is written into the text file via java.
I have Googled a lot but the only results I find are for java and java processing and not for java and javascript (i.e A Client side and Server side)
I am not sure if this is even possible.
More about the question:
I write into the file the crawling results using java and I am trying to display the same using javascript (jQuery.post() method).
JAVA
A multi-threaded crawling program that crawls a website and does some functionality. I am trying to write some content into a text file using the same java program as and when the crawling happens. The content I write mostly are the details about which thread is getting invoked and what is the current link that is being crawled.
The reason I write this in the text file is I need to show the output in the UI so that people looking at the UI will understand what happens.
Writing happens perfectly as expected.
JAVASCRIPT (jQUERY)
This using the
jQuery.get or post ("sample.txt", function (result) {
$("#someID").html(result);
});
It reads from the text file normally but when java and javascript both are trying to access the file, It is the java that dominates leaving javascript behind thus jQuery is unable to fetch the updated content as and when it happens.
I guess this explanation is more than sufficient to make people understand what exactly my problem is !
On the whole, java and javascript try to access the same file at the same time. So there comes this issue.
Any help is appreciated.
Thanks in advance
I think the file is cached. Easiest thing is to request the file by different urls. Try something like "sample.txt?rnd="+Math.rand()
There can be synchronization problems and your data will be corrupted.
I have a question, is it must be done with Ajax? I think you are trying to figure out about
Ajax push and pull
This is not very easy to do and I wouldn't really recommend it. However, there is a better technology called websocket. So what you can do is, client can submit request to the server to write data into a file then server can send back updated content to the client. Moreover, this is much better than achieving the same objective through numerous amount of HTTP requests.
Additionally, if you want the crossbrowser compatibility, have a look at http://socket.io/
Thanks for all those who were trying to help me out.
I have finally come up with a solution. I, instead of using jquery post to directly read from file, am using another jsp file that reads the file contents and prints using out.println on screen, and after which I am using jQuery post to get the content written by that jsp file. Hence the synchronization problem is avoided.
Here is more about my explanation:
Earlier I had
java program -> Text File <- javascript (jQuery post) // Resulted in synchronization problem where in javascript was not able to access the updated content.
Now
java program -> Text file <- JSP file <- javascript (jQuery post) // Avoided the synchronization problem as that file is accessed by the same server side language. After that jQuery reads the content printed by JSP page.
After many changes, finally came up with one good working solution.
Thanks all.

How to read content of scanned pdf file in java / jsp or in javascript

How can i read content of scanned pdf file in java/jsp or in javascript, can you tell how to achieve this with developing code?
advance thanks for reply
You can convert the scanned PDF to a image using GhostScript and then feed it to an OCR engine, such as Tesseract. Take a look at VietOCR for an example implementation.
What you are trying to do (I think) is use OCR to extract text from a image PDF produced by a scanner. Java is probably the best for doing this. There are a number of options for doing this, depending on whether you are prepared to pay for software to do this. Google for Java (or Javascript), PDF and OCR.
IMO, this task is not something that should be done in a JSP. JSPs are best for rendering results ... not for generating them in the first place.
Actually, I am working on the same project at the moment, I am doing this in the following steps and the result works well.
User upload a scanned pdf to PDFUploader servlet, returns a server side file name to front end, which indicates upload is successful.
Front end uses this file name and default page 0 to ask PDFReader servlet to retrieve the first page of pdf file and display is at the front end, you can convert this pdf to a image for use an iframe to have the embedded pdf reader.
Front end uses this file name and default page 0 to ask OCRServlet to perform OCR. I am using WeOCR and tesseract as my OCR engine in an Apache http server. I have modified some parts of the submit.cgi in WeOCR server since I know what types of the format that the WeOCR server will receive. I still have some problems while I convert the scanned pdf to an image (I am using pdfbox )
Google for anything OCR related,
best bet will be to use existing libraries like http://asprise.com/product/ocr/index.php?lang=java

Categories