Google Search with Java [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I am looking into a solution to automate Google Searches using Java. I have looked into the Google Custom Search API but it does not appear to fulfill the requirements. It appears Custom Search requires the domains to be specified ahead of time which does not work for me because I don't know the domains. We want to do a Google Web search, like you would from your browser. Is this possible with the Google Custom Search API? If not does anyone know of any api / library, preferable in Java that would work?

public static void main(String[] args) {
String googleAJAX = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
String searchFor = "stuff";
/**
**Edit:** of course you can also get user input as a string
and search for that instead. i.e.:
String searchFor = (new Scanner(System.in)).nextLine();
**/
URL url = new URL(googleAJAX + URLEncoder.encode(searchFor, "UTF-8"));
Reader read = new InputStreamReader(url.openStream(), "UTF-8");
GoogleResults results = new Gson().fromJson(read, GoogleResults.class);
// Return results (title and URL)
System.out.println(results.getResponseData().getResults().get(0).getTitle());
System.out.println(results.getResponseData().getResults().get(0).getUrl());
}

Selenium - It's portable, scalable and very simple and quick to get started with.
It has libraries for Java and JavaScript whichever you prefer. You can quickly automate what a user would do. For example go to www.google.com and pass in a query string. You can then parse the Object of Elements using XPATH etc (many other methods) to retrieve search results.
You can also get googles autocomplete results by using xpath.
This is not using the google search api, but a custom web automation tool.

Related

Java - How to parse information out of HTML Site? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have a StringBuffer with a HTML Site in it and want to have some specific information of this Site.
1 line is f.e.:
img class="a" data-src="http://test.com" src="" /<
and i want a String with "http://test.com".
Is there a function/parser which can help me?
This is a common question and you could've found the answer with a quick Google search.
Look into Regular Expression (regex) as you'll need it probably more than once.
Consider JSoup framework.
There is "Selector" mechanism to find and operate with html elements.
Jsoup will do the trick, just do a little css and you can get whatever element you need.
Document doc = Jsoup.connect("http://test.com").get();
//DOM Selector CSS String see jsoup docs.
//This will select all image elements with the a class similar to css. IE: img.a
//http://jsoup.org/cookbook/extracting-data/selector-syntax
//Get all elements that are images with class of a
Elements images = doc.select("img.a");
for (Element image : images) {
//Get the url of the image
String url = image.attr("data-src");;
}

Converting time domain to frequency domain in Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have 2 arrays containing time and voltage. I would like to convert time domain to frequency domain in Java. I would like to use FFT. If there is any open source library I could use, please point me to it. I have done a research and found few algorithms but they are asking for real part and imaginary part. If anyone got idea regarding that, please let me know how I could use that in my context.
Code I have found so far
Here is one library:
http://www.fftw.org/download.html
You can also use R with Java. See this link:
Java-R integration?
If you are not familiar with R check their home page r-project dot org (I can't post more links)
While I haven't checked the implementation you link to, you should be able to use that one by suppling 0s for the imaginary part. In that case you are going "forward", i.e. set DIRECT to true transforming from time-domain to the frequency domain. The function will return an array containing real parts of the frequency in even numbered seats, and the imaginary part in odd numbered.

Type-safe "schem based" *hierarchical* configuration read/write library for Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
related to: this question
I want to have type safe front end to configuration files.
In the referred post OWNER Project is suggested. this seems like a great solution - you just need provide the interface with annotations - and the frame word does the rest.
The problem is that the project doesn't support hierarchical configurations, and from the project site it appears it's not expected soon.
Any similar projects that do support this?
EDIT
What i'm looking for is something that will allow me to access a value like:
config.getHost();
instead of:
config.get("host");
I am not sure what you have in mind exactly, but you can use YAML for configuration and you can "deserialize" the data into a data structure of your choice. i.e. the Java objects all type safe. See Snake YAML IMHO YAML is the nicest for hierarchical data as text.
You could try IoC container. E.g. in guice it will be:
class MyClass
{
#Inject #Named("host") String host;
#Inject #Named("port") int port;
}
or with custom annotations:
class MyClass
{
#Inject #Host String host;
#Inject #Port int port;
}
Not quite sure if this is want you mean with type safe, but commons-configuration supports multiple type safe get methods like
Double double = config.getDouble("number");
List<Object> buttons = config.getList("buttons.name");
commons-configuration also supports hierarchical properties
Edit: Didn't see your edit, sorry.
See Bozhos answer on the related question.

Is there a library in Java for SQL like string searches? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking for an api/method/framework where I can compare strings. One is a string stored on the server whereas the other is a string given by user input.
For example:
Stored String : "Login"
User input : "login" "log in" "lOG IN" or any such permutation.
I'm using java in spring mvc (making a webapp). the server is getting a string from the user and then looks for a string similar to the given string and returns the found records.
Any help would be appreciated. Thanks
Unless your data size is small (< a few MB), you probably want something like Apache Lucene, which can be used to index and search large document sets, and can do fuzzy searches using Levenshtein distance and other algorithms for similarity matches.

Library to parse String content based on rules [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I want to add custom logic/class to my custom Jackson JsonSerialize implementation such that it parses out html based on certain rules. For example, if html is inclosed in single quotes '<b>'text'</b>' then the custom logic should accept the string as is. If its not in single quotes, like <b>text</b> then I want the custom logic/class to return just text. Additionally, if I have a block of html enclosed in three single quotes '''<html><head><title>example</title></head></html>''' it should accepted as is but if its not then only the example text should be returned and everything else parsed out. What is the best Java library to accomplish this? I thought about using AnitSamy but that leaves me open to an XSS attack since I need to accept anything inside quotes.
Examples:
input:<b>text</b>
output:text
input:'<b>'text'</b>'
output:'<b>'text'</b>'
input:<html><head><title>text</title></head></html>
output:text
input:'''<html><head><title>text</title></head></html>'''
output:'''<html><head><title>text</title></head></html>'''
You could use the Java Regex engine to look for patterns. Ex:
p = Pattern.compile("'''[\\w*]'''");
m = p.matcher(input);
if(m.find()){
//Do some logic
}
Here's a link to a Java Regex website:
http://www.regular-expressions.info/java.html

Categories

Resources