Open zackb opened 9 years ago
HTML document structure has changed. XPATH needs to be updated
@robertoafjr I have the same problem too, Please fix it, many thanks.
@hustcer this has been fixed and merged
@robertoafjr Thanks very much, when will it work ?
@robertoafjr Hi, you say you merged it. But in the YQL console, it still not working. Is this only my problem ? or it just not updated to the YQL console ? Thanks.
Hi everyone, I do not work for Yahoo! and this is my first contribution to the Open Tables project. I understand from this pull request (https://github.com/yql/yql-tables/pull/444) that my fix had been tested and merged. Although, I am not sure what is the process to have it up and running in the YQL console.
Hi everyone,
I am not sure why it is not working yet. As I understand it, they have merged the code, but maybe haven't deployed it yet?
Anyways, I have placed (below) my fixed version of the yahoo.finance.sectors.xml file. You can make it work by uploading it to your server and calling it from the YQL query as in:
use "http://www.myserver.co.uk/yql/yahoo.finance.sectors.xml" as yahoo.finance.sectors; select * from yahoo.finance.sectors;
This is how I got it to work on my website...
Hope it helps.
Best regards, Roberto Fajardo
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Tom Powers</author>
<description>Yahoo Finance Stock Summary Information</description>
<sampleQuery>select * from {table} where symbol="yhoo"</sampleQuery>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
<url/>
</urls>
<inputs>
<key id="symbol" type="xs:string" paramType="variable" required="true"/>
</inputs>
<execute><![CDATA[
// pad string with leading char
String.prototype.pad = function (padchar, padlen) {
s = this
while (s.length < padlen) {
s = padchar + s;
}
return s;
}
String.prototype.trim = function () {
var str = this.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
function getQuoteInfo() {
// Get company name & market from Yahoo Quotes Summary page
var results = quoteQuery.results;
elements = results.*.length();
if (elements == 0)
return false;
stock.CompanyName = results.h1.text().toString().trim();
var marketSymbolStr = results.div.span.toString();
//var match = marketSymbolStr.match(/^[^:]+:\s+([^)]+)\)$/); matches stock symbol
var match = marketSymbolStr.match(/^\(([^:]+):/);
if (match != null) {
stock.CompanyName += <Market>{match[1]}</Market>;
}
return true;
}
function getHistoricalPrice() {
// Get the Historical Price Range
var results = historicalQuery.results;
elements = results.*.length();
if (elements < 6)
return false;
startMonth = String(parseInt(results.option[0].@value)+1).pad("0", 2);
startDay = results.input[0].@value.toString().pad("0", 2);
startYear = results.input[1].@value.toString();
endMonth = String(parseInt(results.option[1].@value)+1).pad("0", 2);
endDay = results.input[2].@value.toString().pad("0", 2);
endYear = results.input[3].@value.toString();
startDate = startYear + "-" + startMonth + "-" + startDay;
endDate = endYear + "-" + endMonth + "-" + endDay;
stock.appendChild(<start>{startDate}</start>);
stock.appendChild(<end>{endDate}</end>);
return true;
}
function getProfileInfo() {
// Get the Sector, Industry, Full Time Employees from Profile page
var results = profileQuery.results;
elements = results.*.length();
if (elements == 0)
return false;
for each (var tr in results.tr){
//Remove trailing colon, and strip whitespace
var property = tr.td[0].text().toString().slice(0, -1).replace(/\s+/g, "");
switch (property.toLowerCase()) {
case 'indexmembership':
continue;
break;
case 'fulltimeemployees':
//Strip commas
value = tr.td[1].text().toString().replace(/,/g, "");
break;
default:
//Convert whitespace to single space
value = tr.td[1].*.text().toString().replace(/\s+/g, " ");
break;
}
stock.appendChild(<{property}>{value}</{property}>);
}
return true;
}
// Queue the queries
var url = "http://finance.yahoo.com/q/pr?s="+symbol;
var profileQuery = y.query(
"select * from html " +
"where url=@url and " +
"xpath='//table[@class=\"yfnc_datamodoutline1\"]//tr//td//table//tr' " +
"limit 4",
{url:url});
var url = "http://finance.yahoo.com/q?s="+symbol;
var quoteQuery = y.query(
"select * from html " +
"where url=@url and " +
"xpath='" +
"//div[@id=\"yfi_investing_head\"]/h1 | " +
"//div[@class=\"yfi_quote_summary\"]/div[1]'" ,
{url:url});
var url = "http://finance.yahoo.com/q/hp?s="+symbol;
var historicalQuery = y.query(
"select * from html " +
"where url=@url and " +
"xpath='" +
"//option[@selected=\"selected\"] | " +
"//input[@maxlength=\"2\"] | " +
"//input[@maxlength=\"4\"]'",
{url:url});
var stock = <stock symbol={symbol}></stock>;
getQuoteInfo();
getHistoricalPrice();
getProfileInfo();
response.object = stock
]]></execute>
</select>
</bindings>
</table>
The yahoo.finance.sectors query isnt returning results. I believe the structure of the html has changed here: https://github.com/yql/yql-tables/blob/master/yahoo/finance/yahoo.finance.sectors.xml#L30