/ Published in: PHP
http://www.poetiv.com/
Expand |
Embed | Plain Text
<?php require_once("./simple_html_dom.php"); //getAuthorURLs(); //getPoemURLs(); getPoemTexts(); function getAuthorURLs() { //Load html from url $url = "http://www.poetiv.com"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); //output csv file //Create Dom from html $dom = new simple_html_dom(); $dom->load_file( "poetiv.html" ); $div_left_list = $dom->find("#fleft"); //line to debug size of list //echo count($div_left_list) . "\n"; foreach ( $div_left_list as &$div ) { $a_list = $div->find("a"); foreach ( $a_list as &$anchor ) { //put the data into an array and then write array out to a csv file. fputcsv( $csv_out, $csv_array ); } } $div_right_list = $dom->find("#fright"); foreach ( $div_right_list as &$div ) { $a_list = $div->find("a"); foreach ( $a_list as &$anchor ) { //put the data into an array and then write array out to a csv file. fputcsv( $csv_out, $csv_array ); } } //close the csv file output. } function getPoemURLs() { } for ( $i=0; $i<count($author_names); $i++ ) { for ( $j=2; $j<16; $j++ ) { } } } function findPoemURLs( $url, $out, $author_name ) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); $html = new simple_html_dom(); $html->load_file( "./author.html" ); $fleft = $html->find("#fleft"); foreach ( $fleft as &$myFleft ) { $aList = $myFleft->find("a"); foreach ( $aList as &$anchor ) { fputcsv( $out, $poem_row ); } } $fright = $html->find("#fright"); foreach ( $fright as &$myFright ) { $aList = $myFright->find("a"); foreach ( $aList as &$anchor ) { fputcsv( $out, $poem_row ); } } $html->clear(); } } function getPoemTexts() { } $simple = new simple_html_dom(); for ( $i=0; $i<count($poem_urls); $i++ ) { //$simple->load_file( trim($poem_urls[$i]) ); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); $simple->load_file( "./poem.html" ); $pre_list = $simple->find('pre'); $poem_text = ''; foreach ( $pre_list as &$pre ) { } fputcsv( $output_csv, $poem_data ); mysql_query( 'INSERT INTO poetiv_poems ( author_name, poem_name, poem_text, poem_url ) VALUES ( "' . $author_names[$i] . '", "' . $poem_names[$i] . '", "' . $poem_text . '", "' . $poem_urls[$i] . '" )' ); } } } ?>
You need to login to post a comment.
