Search the Community
Showing results for tags 'file_get_html'.
-
Ok I am a complete noob!!! I have done many searches and believe that I have done quite well some what piecing together my script. So I use a forum which has a gear swap section for buying used goods problem is that if you try to search for specific goods then it searches the entire forum. So I found the simple_html_dom class that has the file_get_html method and was able to select only the titles of the listings. I had no problem displaying these listings and then populating a db. Now I want to use if and else-if statements along with regex to grab titles with specific keywords and put them in a corresponding column in my db which I have been unsuccessful at. I'd also like to eventually make my db searchable on my site I'm sure my code could be cleaned up in about every area so if anybody whats to chime in on any part of my code please feel free. It will be much appreciated I have put in many hours and I would like to know that building someone on the right footing lol. you can view my webpage at http://php-ryanlitwiller.rhcloud.com/ - in my page the titles still have their hyperlink but they try to navigate my server...any ideas of how to make them reach the original site? <?php // Open a MySQL connection $link = mysql_connect('127.6.146.130:3306', 'xxxxxxxxxx', 'xxxxxxxxxx'); if(!$link) { die('Connection failed: ' . mysql_error()); } // Select the database to work with $db = mysql_select_db('test'); if(!$db) { die('Selected database unavailable: ' . mysql_error()); } // import simple_html_dom.php to give me various methods for website selection and scraping include('simple_html_dom.php'); // get DOM from BPL URL $html = file_get_html('http://www.backpackinglight.com/cgi-bin/backpackinglight/forums/display_forum.html?forum=19'); // find all td tags with class=forum_listing foreach($html->find('td.forum_listing') as $tdTagExt) //grab just a tags foreach($tdTagExt->find('a')as $aTagExt){ //print selected outertext from previous selectors $refinedTitle = $tdTagExt->outertext; //display nobull listing of goods echo $refinedTitle . '<br>'; //find tent goods using regex to check for the word tent if(preg_match_all('/tent/', $refinedTitle)){ // add matches to corresponding sql coulom $sql = "insert into `bp` (`tent`) values ('$refinedTitle')"; $result = mysql_query($sql); //find sleeping bags using regex to check for the word bag } else if(preg_match_all('/bag/', $refinedTitle)){ $sql1 = "insert into `bp` (`bag`) values ('$refinedTitle')"; $result1 = mysql_query($sql1); //find boots using regex to check for the word boot or shoes } else if(preg_match_all('/boot|shoes/', $aTagExt->innertext)){ $sql2 = "insert into `bp` (`boot`) values ('$aTagExt->innertext')"; $result2 = mysql_query($sql2); //find clothing goods using regex to check for any of the words shirt|pants|parka|shorts|jacket } else if(preg_match_all('/shirt|pants|parka|shorts|jacket/', $aTagExt->innertext)){ $sql3 = "insert into `bp` (`clothing`) values ('$aTagExt->innertext')"; $result3 = mysql_query($sql3); } else { // Create and execute a MySQL query $sql4 = "insert into `bp` (`ahref`) values ('$aTagExt->innertext')"; $result4 = mysql_query($sql4); } } // Close the connection mysql_close($link); ?>
- 10 replies
-
- simple_html_dom
- file_get_html
-
(and 2 more)
Tagged with: