I have been given a screening test for a job and I am stuck at a problem:
I have a website into which I log in and it opens a pop up window which displays stock exchange news in a table format (the columns are: time, type of news, stocks involved, news). The news is updated every minute.
The main objective is to be able to take the news that is displayed and use it in my application.
One solution that I have thought about is if I am able to take the news from the pop up windows and display it in a grid view in my application.
I tried importing it in Excel first using WebQueries but since it is a pop up windows that opens I was unable to do that. Also the website does not have an option to save login information, so you have to enter credentials every time you open the site.
If someone has a solution to this or some different suggestion on how to use the news from the pop up windows in my application please reply. I appreciate your help.
One solution that is very popular is to do XMLHTTPGet to read data from other URLs/Websites. Here is an example to to make XMLHTTP Request
In This example we show times for different time zones on a webpage 'MyServerTime.aspx' joined using ~. function jsTimer() retrieves the times by making XMLHTTPGet (old way of Ajax) to get that times from webpage to display on all other pages.
This way you can read data from any page on internet and extract the necessay information you need form that page by pasring the HTML text you received.
SAMPLE Code
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
var searchReq = getXmlHttpRequestObject();
function jsTimer()
{ getTimes(); }
function handleTimes()
{
if (searchReq.readyState == 4)
{
var str1 = searchReq.responseText;
var x = str1.indexOf('~');
var str = str1.substring(0, x);
}
}
I tried doing what you told me but any website i try to access it gives the error that access is denied. here is the code i wrote based on your example
<script type="text/javascript">
function loadXMLdoc() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function state_change() {
if (xmlhttp.readyState == 4) {
var x = xmlhttp.responseText;
var str = x.indexOf('~');
var str1 = x.substring(0, str);
}
if (xmlhttp.state == 200) {
document.write(str1);
}
else {
alert("Problem");
}
}
</script>
I get this error for any site, google.com is just a example.
Also i have displayed the response text as document.write(), would that be a problem?
sorry for the trouble and thanks a lot for the help.
shah_yash@ho...
Member
12 Points
17 Posts
Importing Data from another website
Jul 08, 2009 07:20 PM|LINK
I have been given a screening test for a job and I am stuck at a problem:
I have a website into which I log in and it opens a pop up window which displays stock exchange news in a table format (the columns are: time, type of news, stocks involved, news). The news is updated every minute.
The main objective is to be able to take the news that is displayed and use it in my application.
One solution that I have thought about is if I am able to take the news from the pop up windows and display it in a grid view in my application.
I tried importing it in Excel first using WebQueries but since it is a pop up windows that opens I was unable to do that. Also the website does not have an option to save login information, so you have to enter credentials every time you open the site.
If someone has a solution to this or some different suggestion on how to use the news from the pop up windows in my application please reply. I appreciate your help.
grid view data access import external data
d.jaspreet
Member
290 Points
60 Posts
Re: Importing Data from another website
Jul 08, 2009 08:19 PM|LINK
One solution that is very popular is to do XMLHTTPGet to read data from other URLs/Websites. Here is an example to to make XMLHTTP Request
In This example we show times for different time zones on a webpage 'MyServerTime.aspx' joined using ~. function jsTimer() retrieves the times by making XMLHTTPGet (old way of Ajax) to get that times from webpage to display on all other pages.
This way you can read data from any page on internet and extract the necessay information you need form that page by pasring the HTML text you received.
SAMPLE Code
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
var searchReq = getXmlHttpRequestObject();
function jsTimer()
{ getTimes(); }
function getTimes()
{
searchReq.open("GET", 'MyServerTime.aspx', true);
searchReq.onreadystatechange = handleTimes;
searchReq.send(null);
}
function handleTimes()
{
if (searchReq.readyState == 4)
{
var str1 = searchReq.responseText;
var x = str1.indexOf('~');
var str = str1.substring(0, x);
}
}
Thanks
JD
asifmaniar
Member
98 Points
62 Posts
Re: Importing Data from another website
Jul 08, 2009 08:28 PM|LINK
You may also want to ask them if they have a Web Service you can talk to and authenticate against that directly.
If thats possible it will be very easy to get whatever information you need to display.
shah_yash@ho...
Member
12 Points
17 Posts
Re: Importing Data from another website
Jul 09, 2009 02:50 PM|LINK
I shall try this out. Thanks for your help.
Yash
shah_yash@ho...
Member
12 Points
17 Posts
Re: Importing Data from another website
Jul 09, 2009 02:54 PM|LINK
Hey Asif,
I tried doing that. They do offer a web service but it is very expensive.
regards,
yash
shah_yash@ho...
Member
12 Points
17 Posts
Re: Importing Data from another website
Jul 10, 2009 04:18 PM|LINK
Hi JD,
I tried doing what you told me but any website i try to access it gives the error that access is denied. here is the code i wrote based on your example
<script type="text/javascript">
function loadXMLdoc() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
var xmlhttp = loadXMLdoc();
if (xmlhttp != null) {
xmlhttp.open("GET", 'http://www.google.com', true);
xmlhttp.onreadystatechange = state_change;
xmlhttp.send(null);
}
else {
alert("Not supported");
}
function state_change() {
if (xmlhttp.readyState == 4) {
var x = xmlhttp.responseText;
var str = x.indexOf('~');
var str1 = x.substring(0, str);
}
if (xmlhttp.state == 200) {
document.write(str1);
}
else {
alert("Problem");
}
}
</script>
I get this error for any site, google.com is just a example.
Also i have displayed the response text as document.write(), would that be a problem?
sorry for the trouble and thanks a lot for the help.
regards,
yash
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Importing Data from another website
Jul 14, 2009 08:34 AM|LINK
Hi shah_yash@hotmail.com,
Not sure what you want. Here is the function for getting page content:
public static string GetResponseText(string url)
{
string responseFromServer = null;
Stream dataStream = null;
StreamReader reader = null;
try
{
WebRequest request = WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusDescription == "OK")
{
try
{
dataStream = response.GetResponseStream();
reader = new StreamReader(dataStream, Encoding.GetEncoding("GB2312"));
responseFromServer = reader.ReadToEnd();
}
finally
{
reader.Close();
dataStream.Close();
}
}
response.Close();
return responseFromServer;
}
catch (Exception ex)
{
return null;
}
}
Hope it helps.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
shah_yash@ho...
Member
12 Points
17 Posts
Re: Importing Data from another website
Jul 27, 2009 05:14 PM|LINK
Thanks Qin,
It works
hasanabbasce
Member
2 Points
1 Post
Re: Importing Data from another website
Feb 14, 2013 07:41 PM|LINK
THANKS QIN IT REALY WORK ,i want to know how to retrive particular data from it. thanks.