Programmaticallyinput to WEB page

HARRY

Active Member
Licensed User
Hi,

I am using the WEBBrowser (Basic4 PPC) to get weather info. The web page returned from the http site contains one and only one input field to enter the name of the location. I would like to enter programmatically the name of the desired location in that field from a list. Does somebody see a possibility to do that?

Harry
 

Basic4Life

Member
Licensed User
Unfortunately the .NET compact framework does not support the HtmlDocument and HtmlElement class, so your control is very limited.
You'd have to do some kind of work around.

The best way in my opinion is to check how the query url looks when you search.
For example weather.com looks like this

B4X:
http://www.weather.com/search/enhancedlocalsearch?where=LOCATION
So you could programmatically build that string and replace "LOCATION" with the location you are looking for and then navigate with the Webbrowser control to that url.

You could post the website you are using, so we can see what's possible.
 

Basic4Life

Member
Licensed User
Hi,

I've got a working solution for you.

Unfortunately the webbrowser control makes it a little too hard to get it working, so I opted for the http library to get the links and then use the webbrowser to display the final weather page for a specific location.
The way the website is set up, requires one to send a post request (not supported in the compact framework wb.navigate method => http lib).

Once we have the search results we parse it for the links and locations, you can select one location and then the webbrowser navigates to that specific weather page. You can programmatically change the location that is searched for, then manually select the location or automatically choose the first result,
or any other way you want to implement it and there's still some room for improvements and optimizations. (you could also insert the searchresults into a html template, if you want to stay in the browser)
Have a look at the weertest_working file in the attachment
the weertest_experimental file shows some other stuff, like using the widgets instead of the website.

The files in the injecting folder that are in the attachment don't work 100% on the device yet

The issue is that the webbrowser control doesn't display the page when it's directly passed from the http response to the wb.DocumentText, they work on the desktop and run in the device IDE, but not compiled on the device. We'll have to figure that out if you want to use one of those implementations.

These files use a different approach, they don't send a post request, they just fetch the website via http lib and insert some code and then pass the website to the webbrowser to display, so all navigating on the website is handled by the browser (since relative links are broken, link clicks are intercepeted in the navigating event and then changed to absolute links).

The html file simply changes the html code to add one location into the input box value,
the javascript file inserts a script that changes the input text
and the htmlform file adds a selectbox to select one out of many locations which then is inserted into the input box.
 

Attachments

HARRY

Active Member
Licensed User
Hi Basic4Life,

Thanks for your support! First to clarify: The locations I am using are in general small towns and villages, as there are our favourite campings. Therefore, I prefer to use weeronline.nl, as weather.com returns in many cases "location not found".

Weer.zip works very well, provided that I use a location for which sub locations exist, e.g. London. When I use a location like Sisteron (a small town in France) then no usefull information is returned, as far as I can see. Also, the string "mobileSearchResultRow" does not exist in the Response. Entering Sisteron in the original http page by hand works very well

I do not know how to proceed further. Apparently you are able to trace the traffic. Do you use specific software to do that?

I would appreciate further help: either some more code to solve my problem or information to enable me to trace the internet traffic.

Regards,

Harry
 

Basic4Life

Member
Licensed User
You're right, the issue is that if the search result is only one location, the response is not the search results page but the actual forecast page for that location.

To solve the problem and improve the approach I changed it a little.
The new version no longer uses the search box of the mobile site to get the data. Instead it's now using the autocomplete feature of the search box of the regular website. The benefits are that instead of handling complete websites, we are now retrieving only the relevant data as a json string. Which makes everything a little more robust and performs faster, because less data has to be transfered and parsed.
Have a look at the attached file weer_NEW.sbp.

If you want to have a look at what your browser is doing in the background, you can use the web console feature in firefox for even more details you can use the tamper data addon

EDIT:

I found another way to solve the problem, it's much closer to what you originally asked, because it allows you to enter text programmatically in to the search box. It only uses the webbrowser library and doesn't need the http lib.
It works by running some javascript in the browser.navigate() method.
It will prompt a script error when running it on the desktop, but not in the compiled version on the device.
For that example, have a look at weer_WB_only.sbp
 

Attachments

Last edited:

HARRY

Active Member
Licensed User
Hi,

The very last solution you gave me is very nice. I take that approach. Of course one more question. When the location has been filled by the Java statements, it is still necessary to click on "VIND" (Find) to get the weather forecast for that location. Is it possible to do that also with one or more Java statements? I am a novice in the Java area.

Harry
 

Basic4Life

Member
Licensed User
Yes, it's possible. If you want it to automatically search for the entered location you can replace this part
B4X:
window.stop();
with
B4X:
searchForm.submit();
 
Top