I want a code to search to google engine for songs via zippyshare . For example the keyword will be "inna sun is up zippyshare" and the first result is this url www32.zippyshare.com/v/55151563/file.html . i want to retrieve the code 55151563 from the the 1st result of google.
Thank you in advance
I will not write the code for you, but I can tip you to the right approach.
Get the url using String search = "http://www.google.com/search?hl=en&q=" + string_to_search;
Download the webpage using URL, InputStream and OutputStream. Check this post here.
Read the file and find the first instance of zippyshare.
Here you can read about xml parsing
Related
I am trying to update the content of a Google Doc file with the content of another Google Doc file. The reason I don't use the copy method of the API is because that creates another file with another ID. My goal is to keep the current ID of the file. This is a code snippet which unfortunately does nothing:
com.google.api.services.drive.Drive.Files.Get getDraft = service.files().get(draftID);
File draft = driveManager.getFileBackoffExponential(getDraft);
com.google.api.services.drive.Drive.Files.Update updatePublished = service.files().update(publishedID, draft);
driveManager.updateFileBackoffExponential(updatePublished);
The two backoffExponential functions just launch the execute method on the object.
Googling around I found out that the update method offers another constructor:
public Update update(java.lang.String fileId, com.google.api.services.drive.model.File content, com.google.api.client.http.AbstractInputStreamContent mediaContent)
Thing is, I have no idea how to retrieve the mediaContent of a Google file such as a Google Doc.
The last resort could be a Google Apps Script but I'd rather avoid that since it's awfully slow and unreliable.
Thank you.
EDIT: I am using Drive API v3.
Try the Google Drive REST update.
Updates a file's metadata and/or content with patch semantics.
This method supports an /upload URI and accepts uploaded media with
the following characteristics:
Maximum file size: 5120GB Accepted Media MIME types: /*
To download a Google File in the format that's usable, you need to specify the mime-type. Since you're using Spreadsheets, you can try application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. Link to Download files for more info.
I'm making Android version of some hebrew website that use WikiEngine but when I try to get some data via it's API using hebrew title names I got wrong answer.
Like if I try to get this URL
http://www.some-web-site.co.il/w/he/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles="HEBREW_TITLE"
I got response from API that title is missing. However if I pass string like this
Blockquote %D7%A1%D7%99%D7%95%D7%A2_%D7%91%D7%A8%D7%9B%D7%99%D7%A9%D7%AA_%D7%9E%D7%9B%D7%A9%D7%99%D7%A8%D7%99_%D7%94%D7%9C%D7%99%D7%9B%D7%94
I got rigth response. This string I got when I copy-paste url from browser. So my question hot can I transfer hebrew topic name to string with this format using Java.
Thanks
Try
String title = "THE_HEBREW_TITLE";
String encodedTitle = URLEncoder.encode(title , "UTF-8");
and use encodedTitle to compose the URL you are using to query the web service.
I am working with Dropbox API using JAVA SDK. I try to get the thumbnail for each image in my dropbox account via API. Honestly, after I read the class and they just provided the description which is not useful enough for the beginner. I begin my code like this
public void getThumbnails() throws DropboxException{
DropboxInputStream dis = api.getThumbnailStream("/Koala.jpg", ThumbSize.ICON_256x256, ThumbFormat.JPEG);
}
What I don't understand is:
I should return something to client side in order to show the thumbnail I got from DropboxAPI but I don't know what I should return. Maybe DropboxInputStream?
How do I get the thumbnail from API? I try to find the example or guide for a day but I can't find any guide...
please someone guide me how to get the thumbnail via dropbox API
DropboxInputStream is just a FilterInputStream so after you get the input stream like you wrote you can just iterate the input stream and read it.
Then it's only a question of the way you need to present it.
Is it a Swing application you are writing? how do you need to show that image?
You should be able to read the Image with ImageIO.read
Image image = ImageIO.read(dis);
http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html
I am using the Selenium 2 Java API to interact with web pages. My question is: How can i detect the content type of link destinations?
Basically, this is the background: Before clicking a link, i want to be sure that the response is an HTML file. If not, i need to handle it in another way. So, let's say there is a download link for a PDF file. The application should directly read the contents of that URL instead of opening it in the browser.
The goal is to have an application which automatically knows wheather the current location is an HTML, PDF, XML or whatever to use appropriate parsers to extract useful information out of the documents.
Update
Added bounty: Will reward it to the best solution which allows me to get the content type of a given URL.
As Jochen suggests, the way to get the Content-type without also downloading the content is HTTP HEAD, and the selenium webdrivers does not seem to offer functionality like that. You'll have to find another library to help you with fetching the content type of an url.
A Java library that can do this is Apache HttpComponents, especially HttpClient.
(The following code is untested)
HttpClient httpclient = new DefaultHttpClient();
HttpHead httphead = new HttpHead("http://foo/bar");
HttpResponse response = httpclient.execute(httphead);
BasicHeader contenttypeheader = response.getFirstHeader("Content-Type");
System.out.println(contenttypeheader);
The project publishes JavaDoc for HttpClient, the documentation for the HttpClient interface contains a nice example.
You can figure out the content type will processing the data coming in.
Not sure why you need to figure this out first.
If so, use the HEAD method and look at the Content-Type header.
You can retrieve all the URLs from the DOM, and then parse the last few characters of each URL (using a java regex) to determine the link type.
You can parse characters proceeding the last dot. For example, in the url http://yoursite.com/whatever/test.pdf, extract the pdf, and enforce your test logic accordingly.
Am I oversimplifying your problem?
I'm currently writing some MATLAB code to interact with my company's internal reports database. So far I can access the HTML abstract page using code which looks like this:
import com.mathworks.mde.desk.*;
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.setCurrentLocation(ReportURL(8:end));
pause(1);
s={};
while isempty(s)
s=char(wb.getHtmlText);
pause(.1);
end
desk=MLDesktop.getInstance;
desk.removeClient(wb);
I can extract out various bits of information from the HTML text which ends up in the variable s, however the PDF of the report is accessed via what I believe is a JavaScript command (onClick="gotoFulltext('','[Report Number]')").
Any ideas as to how I execute this JavaScript command and get the contents of the PDF file into a MATLAB variable?
(MATLAB sits on top of Java, so I believe a Java solution would work...)
I think you should take a look at the JavaScript that is being called and see what the final request to the webserver looks like.
You can do this quite easily in Firefox using the FireBug plugin.
https://addons.mozilla.org/en-US/firefox/addon/1843
Once you have found the real server request then you can just request this URL or post to this URL instead of trying to run the JavaScript.
Once you have gotten the correct URL (a la the answer from pjp), your next problem is to "get the contents of the PDF file into a MATLAB variable". Whether or not this is possible may depend on what you mean by "contents"...
If you want to get the raw data in the PDF file, I don't think there is a way currently to do this in MATLAB. The URLREAD function was the first thing I thought of to read content from a URL into a string, but it has this note in the documentation:
s = urlread('url') reads the content
at a URL into the string s. If the
server returns binary data, s will
be unreadable.
Indeed, if you try to read a PDF as in the following example, s contains some text intermingled with mostly garbage:
s = urlread('http://samplepdf.com/sample.pdf');
If you want to get the text from the PDF file, you have some options. First, you can use URLWRITE to save the contents of the URL to a file:
urlwrite('http://samplepdf.com/sample.pdf','temp.pdf');
Then you should be able to use one of two submissions on The MathWorks File Exchange to extract the text from the PDF:
Extract text from a PDF document by Dimitri Shvorob
PDF Reader by Tom Gaudette
If you simply want to view the PDF, you can just open it in Adobe Acrobat with the OPEN function:
open('temp.pdf');
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.executeScript('javascript:alert(''Some code from a link'')');
desk=com.mathworks.mde.desk.MLDesktop.getInstance;
desk.removeClient(wb);