| | |
Web Page Interaction Question
![]() |
•
•
Join Date: Dec 2008
Posts: 10
Reputation:
Solved Threads: 0
My friend and I are working on a school project and our hope was to have a Java program take a zip code from the user and then connect to weather.com (or any other web site) and look up the local weather. I assume this is possible but I cannot quite figure it out. I am able to get the source code from a site by using the instream, however, it is difficult to find the information I need in the source code. Is there any way to access the page and retrieve the actual text from the site. Thanks!
•
•
Join Date: Dec 2008
Posts: 10
Reputation:
Solved Threads: 0
Well I don't know how to send a request. I just hard coded it by copying the URL from the site after performing a search and then replaced all the places they used the zip in their URL with a variable that contained it. So, I guess I'm stuck at both parts, sending a request as well as retrieving the info.
Sheff21, you need to learn first about HTTP. And how data is sent to a web page via GET or POST.
You send a request to a Web page via the GET or POST method, if you have done some basic web programming or written some forms in HTML you would have encountered them, or you could read about them in the page I have linked to HTTP.
Also once you have cleared your HTTP concepts, Here is an example on how to perform POST in Core Java.
Performing a GET is as simple as appending the the URL with a "?" and then appending the data with the format
You send a request to a Web page via the GET or POST method, if you have done some basic web programming or written some forms in HTML you would have encountered them, or you could read about them in the page I have linked to HTTP.
Also once you have cleared your HTTP concepts, Here is an example on how to perform POST in Core Java.
Performing a GET is as simple as appending the the URL with a "?" and then appending the data with the format
<param1>=<value1>&<param2>=<value2>& ... &<paramN>=<valueN> and invoking it. "Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
Calling a URL and parsing it for plain text values is not what you would want. What you first require is an HTTP API from the site owners which will provide you with proper values. But this certainly requires an API defined at their end and would require you to spare them some usage fees if at all the API exists.
Then a typical interaction between your program and their site would be something like this: You call their URL using either HTTP GET or POST (as mentioned by stephen84s) as specified in their API specification providing them the zip code and they return you the current whether for that zip code as a response.
Then a typical interaction between your program and their site would be something like this: You call their URL using either HTTP GET or POST (as mentioned by stephen84s) as specified in their API specification providing them the zip code and they return you the current whether for that zip code as a response.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
> But this certainly requires an API defined at their end
Not certainly, screen scraping is always an option and which I guess is what the OP is looking for in this case given that it's a school project.
> it is difficult to find the information I need in the source code
As long as you don't abuse the service, XQuery and some other options can make your screen scraping a bit easier.
This involves a two step process:
Not certainly, screen scraping is always an option and which I guess is what the OP is looking for in this case given that it's a school project.
> it is difficult to find the information I need in the source code
As long as you don't abuse the service, XQuery and some other options can make your screen scraping a bit easier.
This involves a two step process:
- Construct a valid HTTP request along with the necessary parameters to query the kind of data you require. Take a look at the HttpClient API offered by Apache.
- Scrape the data from the response returned using various screen scraping techniques.
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- Server with Fedora 9 (Getting Started and Choosing a Distro)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- I got a question... (IT Professionals' Lounge)
Other Threads in the Java Forum
- Previous Thread: please help me to submit my minipro
- Next Thread: Java Applet in another directory
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class client code color component count database derby design eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui homework html ide if_statement image integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia keyword linux list macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object open-source os problem producer program programming project projectideas property read recursion reference replaysolutions ria scanner search server set size sms sort sourcelabs splash sql sqlite stop string swing threads transforms tree ui unicode validation windows






