OK, so I'm using php based simple_html_dom.php found to scrape webpages, and do me What to do is produce a nested list that reflects the HTML element structure of the page. After all, I am planning to start JSTry using that list, but I can not find one in the previous step. I know that there is a simple straight forward solution for this, but I can not know this. I've spent hours searching the web, and finally helped post it here.
Basically I want to change this:
& lt; Body & gt; & Lt; Div id = 'div0' & gt; & Lt; Span id = 'span0' & gt; & Lt; Img id = 'img1' & gt; & Lt; / Span & gt; & Lt; / Div & gt; & Lt; Div id = 'div1' & gt; & Lt; Span id = 'span1' & gt; & Lt; / Span & gt; & Lt; / Div & gt; & Lt; / Body & gt; In:
& lt; Ul & gt; & Lt; Li & gt; Div0 & lt; Ul & gt; & Lt; Li & gt; Span 0 & lt; Ul & gt; & Lt; Li & gt; IMG1 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li & gt; Div1 & lt; Ul & gt; & Lt; Li & gt; Span 1 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt; I think this is an example, it would be correct, but it generates: `
gt; & Lt; Li & gt; `Fatal Error: Call Children to a Member Function on Line 46 on Main.php at a non-object Code:
Include_once ('simple_html_dom.php'); $ Html = file_get_html ("http://www.thefuckingweather.com/"); Create a function ($ url) {print ""; $ Count = 0; Foreign currency ($ url $ s) {if ($ chi-> tag! = "Script") {if (count ($ chi-> children ()) gt; // # 46 {create ($ Chi) - & gt; Children ($ count); } Other {Print ""; }} $ Count ++; }} Create ($ HTML-> Search ("body"));
Understand it, I swear, maybe it happened because I'm so tired. The answer was so easy
include_once ('simple_html_dom.php'); $ Html = file_get_html ("http://www.reddit.com/"); Foreign Currency ($ HTML-> Search ("body") as $ CHE) {test ($ CE); } $ Count = 0; Function Test ($ t) {Print "& lt; ul & gt;"; ($ I = 0; $ i & lt; Count ($ t-> Kids ()); $ i ++) {Print "" for; Print $ t- & gt; Children ($ i) - & gt; ID "-" $ T-> Children ($ i) - & gt; Tag $ count ++; Test ($ t> Kids ($ i)); Print "& lt; / li & gt;"; } Print "& lt; / ul & gt;"; }
Comments
Post a Comment