lawrenceboland Posted August 9, 2007 Share Posted August 9, 2007 I'm trying to extract information out of certain sites such as http://finance.yahoo.com/q/ae?s=TG If I am trying to get specific rows of information out of here (or even all of it), is there an easier way that trying to preg_match my way from html tag to html tag? I'm a php newb.. you don't need to give me all the code, I know thats annoying. I'd just like to know if theres an easier way, and what functions I should use. I'm getting along in my coding, but its slow going trying to preg_match tag by tag. -Bo Quote Link to comment Share on other sites More sharing options...
effigy Posted August 9, 2007 Share Posted August 9, 2007 Depending on the site, you could use an XML parser. Explain your problem further if you need regex help. Quote Link to comment Share on other sites More sharing options...
gurroa Posted August 9, 2007 Share Posted August 9, 2007 I would use stripos and substr. As long as the data are stored in the simple table... $contentofsite = '<html.....</html>'; function GetCont($search, $htmldata) { $_table_start = ($i = stripos($htmldata, '<td><b>'.$search)) !== false ? stripos($htmldata, '<table', $i-100) : -1; if ($_table_start > 0) return ($i = stripos($htmldata, '</table>', $i+6)) !== false ? substr($htmldata, $_table_start, $i-$_table_start+ : 'Not found'; return 'Not found'; } echo GetCont('Earnings Est', $contentofsite); Quote Link to comment Share on other sites More sharing options...
markjoe Posted August 18, 2007 Share Posted August 18, 2007 Are you only trying to get stock prices, volume, etc? Yahoo provides an API (well, kinda) to do this rather easily. I have not done this myself but have seen it done and know tutorials exist to do it. Friend of mine wrote a trading simulator in VB using info from finance.yahoo.com (I'm 95% sure of this anyway), I don't think there was HTML parsing of any kind. I'm thinking it returned comma separated values... Quote Link to comment Share on other sites More sharing options...
lawrenceboland Posted August 18, 2007 Author Share Posted August 18, 2007 Well not ONLY prices and volumes... but pretty much only the stuff that is available on their few pages. I'll have to search for this yahoo finance API. Quote Link to comment Share on other sites More sharing options...
markjoe Posted August 20, 2007 Share Posted August 20, 2007 http://www.gummy-stuff.org/Yahoo-data.htm There it is. It's really not an API, I just don't know what better to call it. It's just a different way to get the same data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.