You need to sign in to do that
Don't have an account?
How do you get a webpage element from an external webpage?
I am trying to capture an element from an external webpage and display it on a visualforce page whenever the text value in a field exists as a value for the external webpage. For example, if I type "GOOG" in the text field, then the page should render the current price for Google's stock.
Here are the details of the task:
1. Create a field to enter the ticker symbol of a stock.
2. Use the inputted ticker symbol to render a call to Google Finance or Yahoo! Finance.
3. Return the quoted price on the webpage to the visualforce page in a field.
4. The page should rerender the current price every 10 seconds.
I currently have the following object and fields:
Object: Stock_SC__c
Fields:
1. Ticker_Symbol_SC__c = text field to capture the desired ticker symbol.
2. Google_Finance_Link_SC__c = formula field that concatenates the base website URL (http://www.google.com/finance?q=) and Ticker_Symbol_SC__c text field.
3. Yahoo_Finance_Link_SC__c = formula field that concatenates the base website URL (http://finance.yahoo.com/q?s=) and Ticker_Symbol_SC__c text field.
The element of Google finance that stores the current price is "<span id="ref_694653_l">1,033.89</span>." For Yahoo! Finance, the element is "<span id="yfs_l84_z">73.06</span>."
Any help is appreciated!
Hi Tylero,
Here is a small sample that I put together on how you can do this using XMLHttpRequest. This uses jQuery.
All Answers
Option 2 - use apex method using http callout (HttpRequest) and return the price value...use actionfunction or call it directly from your command button as per your need...
Hi Tylero,
Here is a small sample that I put together on how you can do this using XMLHttpRequest. This uses jQuery.
Regards,
Satish Kumar
Thank you for the code!
I have written the following so far:
I am getting an error when implementing your code and I can't figure out how to resolve it.
Save error: Syntax error. Missing '}' on line 0
Will you please help with this?
Thank you!
The code is good now. Unfortunately, my browser reports that Yahoo! and Google say "No 'Access-Control-Allow-Origin' header is present on the requested resource" therefore blocking access to Salesforce.com to get the data.
Here is an article that may help you solve this problem. Cross Domain Ajax Request