BASiQ Posted January 30, 2012 Share Posted January 30, 2012 Page I am parsing: http://steamcommunity.com/profiles/76561198010758659/games?tab=all Goal: I am trying to pull a list of hours from the div "game_440" which is Team Fortress 2 Details: Team Fortress 2 has a div ID of game_440. The hours has a heading of <H4> within that div So far I have $html = file_get_dom('http://steamcommunity.com/profiles/76561198010758659/games?tab=all'); echo $html('div#game_440', 0)->getPlainText(); But this outputs more information then I would like as I only want the hours. Not everything else. Team Fortress 2 1951.6 hrs on record Links Visit the Forums Find Community Groups Visit official website Read related news View Stats »๖ۣۜMr.๖ۣۜTeemo™ Achievements »๖ۣۜMr.๖ۣۜTeemo™ Stats Global Achievements Global Leaderboards Recommend... Also, I am hoping for one of two things. Either to be able to pull the links it parses from a list in a text file of full URL's like so $html = file_get_dom('listoflinks.txt'); echo $html('div#game_440', 0)->getPlainText(); Or the ability to have it pull JUST the ID number so I dont have to get the full link $html = file_get_dom('http://steamcommunity.com/profiles/[get:link.no.from.txt]/games?tab=all''); echo $html('div#game_440', 0)->getPlainText(); Either one of these is acceptable, I don't care which one. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/256065-parsing-a-heading-within-a-div/ Share on other sites More sharing options...
Zane Posted January 30, 2012 Share Posted January 30, 2012 If you only want the H4, then shouldn't you just be able to select it? $html('div#game_440 h4', 0)->getPlainText(); Quote Link to comment https://forums.phpfreaks.com/topic/256065-parsing-a-heading-within-a-div/#findComment-1312718 Share on other sites More sharing options...
BASiQ Posted January 30, 2012 Author Share Posted January 30, 2012 Well, aint that nice xD I am new to PHP so I did not know I could do that =) Thanks for that one. Now all I need to do is learn how to parse from a list of URL's Which there seems to be a serious lack of assistance available for this online. Maybe it can't be done. Quote Link to comment https://forums.phpfreaks.com/topic/256065-parsing-a-heading-within-a-div/#findComment-1312720 Share on other sites More sharing options...
Zane Posted January 30, 2012 Share Posted January 30, 2012 put the Urls inside an array.. then use foreach to do your DOM scraping. Also, the solution I provided had nothing to do with PHP, ... take a look at DOM selecting... or CSS selecting for a better understanding. Quote Link to comment https://forums.phpfreaks.com/topic/256065-parsing-a-heading-within-a-div/#findComment-1312724 Share on other sites More sharing options...
BASiQ Posted January 30, 2012 Author Share Posted January 30, 2012 Yeah, I know it has to do with DOM. I am using it already to get what I had to begin with. Your script worked like a charm. I am going to research array's now. Also, I have one more thing I am hoping to do eventually. At this moment, it outputs plaintext. Which is great, but if I could get it to also output the link which provided the results at the end of each result that would also be great =) I am going to research a bit and see what I can figure out first Quote Link to comment https://forums.phpfreaks.com/topic/256065-parsing-a-heading-within-a-div/#findComment-1312730 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.