Welcome Guest, Not a member yet? Register   Sign In
Help With Screen Scraping (Need To Find Date On Page)
#5

[eluser]Jay Logan[/eluser]
Thanks for all the help. This is what I ended up doing.

First, needed to get rid of all new line characters and any characters that create white space.

Code:
$html = file_get_html($this->input->post('url'));
$new_lines = array("\t","\n","\r");
$content = str_replace($new_lines, "", html_entity_decode($html));

Next I find the first instance of a certain pattern (code where the date and time is displayed).

Code:
preg_match("|<hr>(.*)<br>|U", $content, $raw_date);

Then I remove the text/code before the date & time that I don't need.

Code:
$format_date_front = str_replace('<hr>Date: ', '', $raw_date[0]);
$format_date_back = str_replace('<br>', '', $format_date_front);

And finally I separate the date and time to insert in separate database fields.

Code:
$date_time = explode(', ', $format_date_back);
$date = trim($date_time[0]);
$time = trim($date_time[1]);


And the final code (with other stuff) ends up giving me a pretty awesome tool that lets me simply paste the link of a Craig's List and insert data from the post into my database - creating a nice list of all my posts from several different accounts. I track hits, posting duration, clicks to inserted links, ad status, and other stuff. CI is the best.


Messages In This Thread
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-04-2009, 02:57 PM
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-04-2009, 03:02 PM
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-06-2009, 05:32 AM
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-11-2009, 10:01 AM
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-11-2009, 10:36 AM
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-11-2009, 11:18 AM
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-11-2009, 11:20 AM
Help With Screen Scraping (Need To Find Date On Page) - by El Forum - 08-11-2009, 11:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB