Web scraping on silverlight 4 page - silverlight

There is a web page with a silver light application embedded and I want to scrape it. I wonder if there is a web scraping solution or browser automation solution (or any trick/hack) that supports silverlight in either C#, Java or Python.
I am currently trying silvernium but it is quite outdated project and doesn't seem to work properly with silverlight 4.
Here is some of the html information of the SL object in the page:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="PATH/WebSilverlight.xap"/>
<param name="onerror" value="onSilverlightError"/>
<param name="background" value="white"/>
<param name="minRuntimeVersion" value="4.0.50524.0"/>
<param name="autoUpgrade" value="true"/>
<param name="windowless" value="true"/>
<param name="enableautozoom" value="true"/>
...

I have worked successfully with Telerik testing framework for an
automation solution that supports silverlight in C#
It's free and once you get to used to it - very easy, because of the rich API and the cross-browser compatibility. Maybe the trickiest part is to initially config the tests.
Simple example:
Settings mySettings = new Settings();
mySettings.Web.DefaultBrowser = BrowserType.InternetExplorer;
Manager myManager = new Manager(mySettings);
myManager.Start();
myManager.LaunchNewBrowser();
myManager.ActiveBrowser.NavigateTo("http://www.example.com");
Element mybtn = myManager.ActiveBrowser.Find.ByTagIndex("input", 3);
myManager.ActiveBrowser.Actions.Click(mybtn);
myManager.Dispose();
A good addition to it is the Windows Inspect tool. It'll enable you to select any UI element and view the element's accessibility data in some tricky cases.
Update:
I've searched some helpful documentation links that I've used back in the days. Look at Getting started with Silverlight UI Automation and Locating elements.

In the end, I implemented a workaround using the computer vision based technology SikuliX and getting a printed PDF out of the Silverlight web app like normal normal user would to get the information. Here is an script that shows how to run this along with Selenium.
Another alternative is to hack the requests and keep the session alive while navigating to the information you need using either Scrapy, abot, crawler4j or any other similar technology.

Related

Loading XAP based on Silverlight Version

I have a Silverlight application running across many different locations. I want to upgrade to Silverlight 5 but unfortunately several of our large sites have antiquated IT departments that are dragging their feet on the upgrade. They're telling me it's going to be at least 4-6 months before than can be running Silverlight 5. What I'm wondering is this: Can I build a Silverlight 4 version of my XAP and a Silverlight 5 version of my XAP and then load the correct version based on which version of the Silverlight client is running on the machine accessing my site.
Is this even possible? I've searched around and I didn't see anything pointing me in the right direction so I came here.
Thanks
It's certainly possible to choose to load a different XAP depending on the version of the Silverlight plugin the user has. The key is to use the Silverlight.isInstalled JavaScript function.
You'll need to make a couple of small modifications to the HTML used to display your Silverlight application:
add an ID such as id="slObj" to your Silverlight <object ...> element.
remove the element <param name="source" value="...">. The value of this parameter will be determined at runtime by JavaScript.
Once you've done that, you can call a function such as the following to load the correct Silverlight application. I've assumed your Silverlight HTML <object> element has an id of slObj:
function loadCorrectSilverlightXAP() {
var slObj = document.getElementById("slObj");
if (Silverlight.isInstalled("5.0.0.0")) {
slObj.source = "URLOfMySilverlight5App.xap";
} else {
slObj.source = "URLOfMySilverlight4App.xap";
}
}

EnableCacheVisualization not working

I know I've made this work before but now I don't know what I am doing wrong.
I create a new hosted Silverlight application.
I added a button object on the MainPage.xaml setting CacheMode="BitmapCache"
I edited my default.apsx file to add the following lines to the silverlight object tag :
<param name="EnableCacheVisualization" value="true" />
<param name="EnableGPUAcceleration" value="true" />
<param name="EnableFrameRateCounter" value="true" />
But I cannot see neither the FrameRateCounter or the CacheVisualization... What am I doing wrong here.
Thanks
Make sure the Web Application is set as the startup project and that the Default.aspx is its start page. Also check that your app is compiling without error in some cases VS will just continue and run the original XAP when compiling a new one fails.
Maybe you have some startup code somewhere that sets those options back to False?
Try adding a button which shows the value of System.Windows.Interop.Settings.EnableCacheVisualization.
Otherwise, can you post your html page source?
Thank you both for your help, but I got my answer... It is really stupid, but those functions are not working with "Windows Server 2008"!!! I changed my workstation recently and wasn't aware of that.
got my answer here : http://msdn.microsoft.com/en-us/library/dd833062(v=VS.95).aspx
Hardware acceleration is only enabled on Windows Vista, Windows 7, and
Windows XP. On Windows XP NVidia, ATI, Intel cards with a driver date
post November 2004 is required for hardware acceleration.

Silverlight 5 - 3D - RenderModeReason - TemporarilyUnavailable

I'm trying to create a simple Silverlight 3d application...
I have a good enough PC, but when I run the Silverlight application I get this:
RenderModeReason - TemporarilyUnavailable... WTF is that? o_O
PS: The sample 3D applications where made by MS and are compiling and working.
In order to be able to use 3D acceleration in your app (and all the XNA namespaces), you must enable HardwareAcceleration during plugin initialization. Fortunately, it's easy:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
[...]
<param name="enableGPUAcceleration" value="true" />
[...]
</object>
To enable GPU acceleration for Out of browser apps, set the enable GPU acceleration option on the project property page.

Delivering Silverlight in HTML object or embed tag base64 encoded data

It is possible to base64 encode an image and deliver it as part of the html content using the <img src="data:image/gif;base64,UEsDBBQAAAgIALp9...MTs9Snj3==">
I notice that Silverlight's object tag is supposed to be something like:
<object type="application/x-silverlight"
data="data:application/x-silverlight;base64,"
width="300" height="300">
<param name="source" value="myApp.xap"/>
<object>
and it seems that I should be able to just put in this, using the same technique as with the images:
<object type="application/x-silverlight"
data="data:application/x-silverlight;base64,SOFIjoije3r8...WMDioaAAA=="
width="300" height="300">
<object>
And have it load the xap file data from the base64 encoding in the data parameter. But this doesn't work - it loads the Silverlight plugin and there are no errors in IE or Firefox, yet the xap module isn't run.
I know browsers can be very picky about syntax for this kind of thing, so I'm asking y'all.
The purpose is to embed Silverlight in a asp.net Server Control without the additional complexity for the developer of having to host the xap somewhere and to resolve the uri of the xap, etc. I'm primarily interested in loading the xap from the embedded base64 encoded string, but if that cannot be done, good solutions for simplifying the use of the Silverlight app to a single-line of code will have to do.
Thanks!
Even if you were to get it to work, I recommend against that approroach for the following reasons:
The time that it takes to load the entire page would be long
This doesn't take advantage of any browser caching of the XAP so that every time the page loads, the xap must be read.
I appreciate the time you all took to look at my question. I found the "better solution" to be the WebResource.axd - it provides us the ability to load resources directly from a properly decorated assembly merely by its being present. This is perfect. I figured that I'd have to require consumers to add all kinds of garbage to the web.config for custom httpHandlers or something, but it turns out that WebResource.axd is included as of asp.net 2.0 for this purpose.
Here's the article I found explaining it all:
https://web.archive.org/web/20211020131200/https://www.4guysfromrolla.com/articles/080906-1.aspx

Silverlight 2.0 binding to images vs. Silverlight 3.0

I have a Silverlight 2.0 application which binds a listbox to a collection of classes that contain a BitMap property (which are used for navigation). I've both included the images in the XAP as content and created the BitMap manually and set it as the controls source and I have also embedded the images as resources in the DLL and got the image from the manifestresourcestream and set the image. Both of these routes work great when the XAP is displayed using the Silverlight 2.0 plugin so I know my images are being deployed correctly. Unfortunately, when viewed on a machine with the Silverlight 3.0 plugin, neither of these methods display the images in the listbox.
Note that this problem only occurs when the binding takes place in an ItemTemplate of a Listbox. If I set the same property outside of the listbox it appears to find the images and work fine.
Any idea what has changed in ListBox binding between 2.0 and 3.0? I do have build 3.0.40307 of the Silverlight plugin on the machine I can reproduce the error on.
-Kevin
Ok...a solution was found (thanks to some help on the Silverlight boards):
First, it only works with the full release of the Silverlight 3.0 plug-in. Which poses a strange problem (described below).
Second, I had to switch from binding directly to an Image or Bitmap class and instead use an Imagesource class (which can be easily instantiated with a Bitmap passed to the constructor). Simple enough... Don't know why this is required in SL 3.0 but not 2.0 but it broke my code. My code is still written and compiled against the 2.0 plug-in but just runs in the 3.0 plug-in on computers that have it.
Which brings me to the strange issue...I have VM's or desktops with SL 2.0, SL 3.0 (Beta), and SL 3.0 (Full Release) available for testing. My plug-in now works fine in SL 2.0 and SL 3.0 (Full Release) but not in SL 3.0 (Beta). I get no warning and it opens fine, just that my images do not bind. So my concern is that a number of developer/techy oriented people will have the beta of 3.0 which still runs 2.0 plug-ins as it's backward compatible. They aren't forced to upgrade for any reason to run my site.
If you have any of these environments available here is a link to the site in question: http://stlouisdayofdotnet.com/DayOfDotnet.html

Resources