PHP - Need Help For Fixing Html When Scrape Using Php Simple Html Dom Parser
require_once 'phpSimpleHtmlDomClass.php'; $html = '<div> <div class="man">Name: madac</div> <div class="man">Age: 18 <div class="man">Class: 12</div> </div>' $name=$html->find('div[class="man"]', 0)->innertext; $age=$html->find('div[class="man"]', 1)->innertext; $cls=$html->find('div[class="man"]', 2)->innertext; wanna get a text from each div class="man" but it didn't work because there is a missing closing div tag on 2nd line of html code. please help me to fix this. thanks in advance. Similar TutorialsHi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone im using simple_html_dom.php i want to extract the following html: and number the array key so i will know the location of each <td> and extract the value the this cell: <TD ALIGN=RIGHT NOWRAP class="ftableline1"> 3.7200 </TD> with this : Code: [Select] foreach($html->find('td[class=ftableline1]') as $e) echo $e->innertext . '<br>'; Code: [Select] <TR class="ftableline1"> <TD ALIGN=RIGHT NOWRAP class="ftableline1"> 3.7200 </TD> <TD ALIGN=RIGHT NOWRAP class="ftableline1"> 3.5400 </TD> <TD ALIGN=RIGHT NOWRAP class="ftableline1"> 3.6651 </TD> <TD ALIGN=RIGHT NOWRAP class="ftableline1"> 3.5982 </TD> <TD align="right" NOWRAP class="ftableline1"> <A HREF=_matbea=1><IMG SRC="images/tezuga_graphit.gif" WIDTH=15 HEIGHT=15 ALT="Show Graph" BORDER="0"></a><BR> </TD> <TD ALIGN=RIGHT NOWRAP>0.01%</TD> <TD ALIGN=right dir="rtl"> <IMG SRC="images/arrow_up.gif" WIDTH=10 HEIGHT=8 BORDER=0><BR> </TD> <TD align="right" NOWRAP dir="rtl" class="ftableline1"> 3.6316 </TD> <TD align="right" NOWRAP dir="rtl" class="ftableline1"> 1 </TD> <TD ALIGN=RIGHT NOWRAP dir="rtl" class="ftableline1"> <A HREF=_matbea=1> דולר ארה"ב</A><BR> </TD> <TD align="right" NOWRAP dir="rtl" class="ftableline1"> <A href="_matbea=1"><IMG SRC="../../meida/images/f1.gif" HEIGHT=15 WIDTH=21 border=0></A><BR> </TD> <TD ALIGN=center NOWRAP dir="rtl"><INPUT TYPE="Checkbox" VALUE="1" NAME="check" id="check" ></TD> </TR> Hello dear Community, i have a document i need to parse it and spit out only this part of the table: see http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=67003&lschb= how to i parse the stuff!? With perl or php? Note i have the xpaths (see below) Sad that i cannot apply them on Simple DOM Parser since this Dom Parser does not work with Xpaths but with CSS-Selectors: Well i want to get all the data with that are within the table that name is called class="fliess" How to dump all the results? BTW - thinking about the most elegant way, i think it is the most pretty way would be to do it with perl - So i can try it with HTML::TableExtract or.... Well what do you suggest - Which way to choose to do this [very] simple thing? Look forward to hear from you! see the xpaths: Schule: /html/body/center/table/tbody/tr[2]/td[1] Stasse: /html/body/center/table/tbody/tr[3]/td[1] Ort: /html/body/center/table/tbody/tr[4]/td[1] Tel: /html/body/center/table/tbody/tr[5]/td[1] Schulgliederungen: /html/body/center/table/tbody/tr[6]/td[1] Besonderheite: /html/body/center/table/tbody/tr[7]/td[1] E-Mail: /html/body/center/table/tbody/tr[8]/td[1] Schulnummer: /html/body/center/table/tbody/tr[9]/td[1] Hi All, I am using the PHP Simple HTML DOM parser to connect to a financials website, parse out a companies financial information (Income statement in this case) and then insert the scrapped data into a mysql database that I can then later use to run automated calculations. Here is the code I have so far: Code: [Select] <?php include_once 'simple_html_dom.php'; //Connect to financial Website and Create DOM from URL $income_statement = file_get_html('http://www.WEBSITE.com/finance?etc..etc...etc...etc...'); //PULL FINANCIAL DATA foreach($income_statement->find('td[class]' ) as $lines=>$data) { echo $data->plaintext . "<br/>"; } // clean up memory $html->clear(); unset($html); ?> So far I am able to get output that looks like this: Code: [Select] Revenue 336.57 331.52 324.32 319.29 320.40 Other Revenue, Total - - - - - Total Revenue 336.57 331.52 324.32 319.29 320.40 etc............................. But being a newb I do not understand how I can break each $ value and each - into their own variables and then insert them to their corresponding mysql table fields. During the database insert I would like to ignore field headings from insertion (i.e Revenue, Total Revenue, etc.... Any help would be absolutely amazing, as I have been reading, scripting and searching for information like crazy, but just can't seem to figure it out. hello dear community, i am currently wroking on a approach to parse some sites that contain datas on Foundations in Switzerland with some details like goals, contact-E-Mail and the like,,, See http://www.foundationfinder.ch/ which has a dataset of 790 foundations. All the data are free to use - with no limitations copyrights on it. I have tried it with PHP Simple HTML DOM Parser - but , i have seen that it is difficult to get all necessary data -that is needed to get it up and running. Who is wanting to jump in and help in creating this scraper/parser. I love to hear from you. Please help me - to get up to speed with this approach? regards Dilbertone Hello dear friends, first of all : merry merry Xmas!!! i want to parse with the simple Simple HTML DOM Parser, well i am pretty new to php and to the Simple HTML DOM Parser. My example: http://schulen.bildung-rp.de/gehezu/startseite/einzelanzeige.html?tx_wfqbe_pi1[uid]=60119 I want to collect the data in the block: I have investigated the sourcecode - and found out that the attribute of interest should be this one: class="content"div class="content"><!-- TYPO3SEARCH_begin --> here the code is: - my trails. // inculde the Simple HTML DOM Parser include_once('simple_html_dom.php'); // get the file we want to parse right now,create a DOM $html = file_get_html(''); // simple_html_dom::find() creates a new // simple_html_dom-Objekt, that consists out of // corresponding childelements foreach($html->find('class: content ') as $h3) { // simple_html_dom::get the text in a tag // den Text innerhalb eines Tags if($h3->innertext == 'Text of a H3 Tag') { break; } } // simple_html_dom::next_sibling() gives the // next Element $table = $h3->next_sibling(); but believe me - it gives me not back what is aimed. what have id done wrong...? dbone good day dear community, this is a big issue. I have to decide: between native PHP DOM Extension or of simple DOM html parser well i want to parse the site he http://buergerstiftungen.de/cps/rde/xchg/SID-A7DCD0D1-702CE0FA/buergerstiftungen/hs.xsl/db.htm http://buergerstiftungen.de/cps/rde/xchg/SID-A7DCD0D1-702CE0FA/buergerstiftungen/hs.xsl/db.htm I will suggest to use the native PHP "DOM" Extension instead of "simple html parser", since it will be much faster and easier What do you think about this one here...: Code: [Select] $doc = new DOMDocument @$doc->loadHTMLFile('...URL....'); // Using the @ operator to hide parse errors $contents = $doc->getElementById('content')->nodeValue; // Text contents of #content look forward to hear from you best regards db1 I'm using PHP 5.2 Server and Simple HTML DOM 1.5. This script scrape or extract data from a football site, its fully working on PHP 5.9 Server but I need to know how I can fix it for PHP 5.2 server. Can someone give me a hint on how can I fix the error? Thanks in advance. My PHP 5.2 Server script output shows: ++++++++++++++++ Object id #599 Object id #604 Object id #609 Object id #614 Object id #619 Object id #627 Object id #632 Object id #637 Object id #642 Object id #647 Object id #655 Object id #660 Object id #665 Object id #670 Object id #675 Object id #683 Object id #688 Object id #693 Object id #698 Object id #703 Object id #711 Object id #716 Object id #721 Object id #726 Object id #731 ++++++++++++++++ while PHP 5.9 Server says ++++++++++++++++ Rk Player Team POS OPPONENT 1 Aaron Rodgers GB QB at CAR 2 Tom Brady NE QB vs. SD 3 Matt Schaub HOU QB at MIA 4 Michael Vick PHI QB at ATL ++++++++++++++++ I did applied the bug solution listed on https://sourceforge.net/tracker/index.php?func=detail&aid=3107230&group_id=218559&atid=1044037 but it is still not working. It says: ++++++++++++++++ Details: I get compiler errors in PHP 5.2 when using this as an object. The offending lines are 609 and 940, which both contain this construct: if ($this->size>0) $this->char = $this->doc[0]; This tries to get the first character of $this->doc, but PHP 5.2 sees it as trying to access it as an array. It's easily fixed by this: if ($this->size>0) $this->char = substr($this->doc, 0, 1); Or you could probably use chr(ord($this->doc)) as well. Either way solves the compile error without changing functionality. ++++++++++++++++ Here are my codes: Code: [Select] <?php # don't forget the library include('simple_html_dom.php'); # this is the global array we fill with article information $articles = array(); $source = 'http://www.athlonsports.com/columns/winning-game-plan/fantasy-football-qb-rankings'; # passing in the first page to parse, it will crawl to the end # on its own getArticles($source); function getArticles($page) { global $articles, $descriptions; $html = new simple_html_dom(); $html->load_file($page); //$items = $html->find('div[class=preview]'); $items = $html->find('tbody tr'); foreach($items as $post) { # remember comments count as nodes /*$articles[] = array($post->children(3)->outertext, $post->children(6)->first_child()->outertext);*/ $articles[] = array($post->children(0), $post->children(1), $post->children(2), $post->children(3), $post->children(4)); } # lets see if there's a next page if($next = $html->find('a[class=nextpostslink]', 0)) { $URL = $next->href; echo "going on to $URL <<<\n"; # memory leak clean up $html->clear(); unset($html); getArticles($URL); } } ?> <html> <head> </head> <body> <? echo "Source: " . $source; ?> <table cellpadding="5" cellspacing="0" border="0"> <?php foreach($articles as $item) { echo "<tr>"; echo "<td>" . $item[0] . "</td><td>" . $item[1] . "</td><td>" . $item[2] . "</td>"; echo "<td>" . $item[3] . "</td><td>" . $item[4] . "</td>"; echo "<tr>"; } ?> </table> </body> </html> Im using some software called php html dom parser i wont to be able to keep the souce tidy i.e before dom parser <?php //////////////////////SEO TOOL/////////////////////////// $title = 'Green Deal Nationwide - PB Energy Solutions Ltd'; $description = 'Delivering all your environmental needs to \'green\' up your business, improve reputation, increase profitability and give a competitive advantage.'; /////////////////////////////////////////////////////// ?> <?php include('includes/settings.php'); ?> <?php include('includes/header.php'); ?> <div class="container"> <div id="large-page-img"> <img src="<?php echo URL(); ?>images/home-page-slide.jpg" width="911" height="230" /> <img src="<?php echo URL(); ?>images/home-page-slide-1.jpg" width="911" height="230" /> <img src="<?php echo URL(); ?>images/home-page-slide-2.jpg" width="911" height="230" /> </div> <div id="content-home"> <div class="iedit"> after dom parser saved to file <?php //////////////////////SEO TOOL/////////////////////////// $title = 'Green Deal Nationwide - PB Energy Solutions Ltd'; $description = 'Delivering all your environmental needs to \'green\' up your business, improve reputation, increase profitability and give a competitive advantage.'; /////////////////////////////////////////////////////// ?> <?php include('includes/settings.php'); ?> <?php include('includes/header.php'); ?> <div class="container"> <div id="large-page-img"> <img src="<?php echo URL(); ?>images/home-page-slide.jpg" width="911" height="230" /> <img src="<?php echo URL(); ?>images/home-page-slide-1.jpg" width="911" height="230" /> <img src="<?php echo URL(); ?>images/home-page-slide-2.jpg" width="911" height="230" /> </div> <div id="content-home"> <div class="iedit"><div class="iedit"> is there anyway i can keep it like the original fil after dom? how should i approach the following: a page with a products list+link to product page i want to build a crawler that loops through all the products in the list and goes to the product page and and parses the product page. need help with the loop Hi everyone. I've two MySQL tables (tbl_csv_input & tbl_qn_types). Table Details: 1. tbl_csv_input (qid, qname, qn_answer, qn_type) Primary Key = qid; Foreign Key = qn_type ref tbl_qn_types qn_type_id 2. tbl_qn_types (qn_type_id, qn_type_name, notes) Primary Key = qn_type_id Sample Data: tbl_csv_input 1 ; Ferrari is the fastest car? ; Yes||No ; T1 2 ; Which below features would you like to have in you... ; Navigator||Airbag||Seat Belt||Camera & Sensors ; T1 3 ; Which model would you prefer? ; CX||MX||SX||LX ; T2 4 ; Comments ; ; T3 tbl_qn_types T1; checkbox; This qn type is used for yes/no T2; radio; Multiple options but only one is correct T3; text area; Users enter input like comments The whole idea is to have a questionnaire displayed in a HTML table depending upon the question types (T1, T2, T3) In simple terms: You have a question and below it there are options. Some questions have check boxes and some have radio buttons and some have text areas. The problem I'm facing is with the column: qn_answer; and column = qn_type. I'm unable to make a loop inside a table which is already in a loop. Please see the attached files (which has the code I've written). TIA. [attachment deleted by admin] suppose a page has the following tags Code: [Select] <div class = "news"> <div class = "article"> <h2>title 1</h2> <div class = "content"> <p>content 1....</p> </div> </div> <div class = "article"> <h2>title 2</h2> <div class = "content"> <p>content 2....</p> </div> </div> </div> is it possible to check, using simple html dom library, whether the value of <h2> is title 1 and then if it is echo it, or store it in a variable? what i've been able to do up to now is: <?php include('simple_html_dom.php'); foreach($article->find('div[class=news]') as $news) { foreach ($news->find('div[class=article]') as $content) { foreach ($content->find('h2') as $heading) { echo $heading; } } } ?> this only echos all the h2 so say I want to make a url decoder and put it on my website [php] <?php $url = "url"; $urldecode = urldecode($url); [\php] I want there to be an entry box for somenoe to put the url in, a submit button so they put the url in and hit submit then a box to display the new decoded url any help with this? Thanks Guys I m trying to make a crawler and the crawler works fine but the problem is that after some random amount of time the crawler crashes with the message "PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in ....." . Please help me out . Is it my code or there is a problem with simple html dom ?? Hiya! I need to create a simple PDF script that will always create A4 documents. I need the content to be controlled using HTML and CSS. Where do you start in creating such a script? Any help is greatly received. Hello, can any1 show me how to insert the following in db Code: [Select] <?php include('dbconnect.php'); include('simple_html_dom.php'); $html = file_get_dom('test3.php'); foreach($html->find('h2') as $heading) { //echo $heading; foreach ($heading->find('a') as $link) { $item_title = md5($link); echo $link."<br/>"; $sql = "INSERT INTO articles(article_id, article_link) VALUES($item_title, $link)"; $result = mysql_query($sql); } } ?> what i want to do is insert every link in the db, but this is not working. The output is ok but the insert doesnt work. Any help please?? All some help would be welcome. I'm having troubles with this simple email script. the idea: would like to make a mailing from a form. This works just fine. I'm having troubles with the mailing it self. What i posted he I edited my code to try without concatenating strings (*$_Post varible within xml). This however doesn't work eitherway. tests: all variables get set properly (tested with echo's so I cut them out to save you the reading :-)) connection gets established just fine All email adresses from the database pass by just fine. (also by echo :-)) I'm thinking semantic error but can't find the problem. Can anyone help me? <?php //make connection with database $con = mysql_connect("XXXXXXXXX","XXXXXXXXXX","XXXXXXXX"); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("dejuistestudiek", $con); //select all emails from mailing table if($con){ $sql = "SELECT * FROM mailing"; $result = mysql_query($sql); //prepare text for html mail $text = trim($_POST['TEXT']); $text = nl2br($text); $text = stripslashes($text); if($result){ while($row = mysql_fetch_array($result)){ // single recipient $to = $row['email']; // subject $subject = 'StuWay - Nieuwsbrief'; // message $message = '<html> <head> <title>Birthday Reminders for August</title> </head> <body> <p>Here are the birthdays upcoming in August!</p> <table> <tr> <th>Person</th><th>Day</th><th>Month</th><th>Year</th> </tr> <tr> <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> </tr> <tr> <td>Sally</td><td>17th</td><td>August</td><td>1973</td> </tr> </table> </body> </html>'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Do-Not-Reply@dejuistestudiekeuze.be' . "\r\n"; // Mail it $bool = mail($to, $subject, $message, $headers); } } } ?> I have a quick question to ask, as i cant see it in their docs. Maybe you can help me. I am using http://simplehtmldom.sourceforge.net/ Right, i have written a Simple HTML Dom script to collect data from this page, as an example: http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.html Script executed by running a cron job on this file (which generates the XML): http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.php The data is collected, and written to this file in XML file: http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.xml Thats is fine, and the script essentially scrapes the entire page, with no conditional IF's for any sections. A sample of my code for one segment is below: http://pastebin.com/JLb8f92N What i would like to do now, and i am hoping you could help out is... Scrap this same page, but produce seperate XML files, based on the date. So if you view that page, i want to scrape the data in the table Saturday 4th February 2012 and produce XML for for that day only. The i want to scrape the data in the section for Sunday 5th February 2012, and another for Tuesday 7th February 2012. I think its self explanatory. The table date sections are separated by this HTML element: bg color = " #CCCCCC " But bare in mind that the table rows on each date section will change when the site is updated, and there may be additional or less football game records. Anyway, i would appreciate any help you can show me, on how to place in any conditionals in the code, and only scrape the date sections needed. Separate script files would be fine if it was needed. Many thanks for your time, Darren. |