コード例 #1
0
    //$char_compare = $full_string[$negative_string_length];
    $char_compare = 'a';
    // While haven't found 'f' and haven't reached the beginning of the string
    while ($char_compare != 'f' || $string_length < 0) {
        // Traverse backwards to get beginning of number
        $char_compare = $full_string[$string_length];
        echo "char compare is: " . $char_compare . "\n";
        $string_length--;
        echo $string_length . "\n";
    }
    // Go forward til getting to "1"
    $char_compare = $full_string[3 + $string_length];
    echo "char compare is: " . $char_compare . "\n";
    return $char_compare;
}
$char_at_now = GetTotalResults($total_results);
echo "char at now is: " . $char_at_now . "\n";
echo "string_length now is: " . $string_length . "\n";
// pull company name
//$company = $html->find("div.modlinks a", 0);
for ($i = 0; $i < 10; $i++) {
    ////$company = $html->find("span.coname2 a", $i);
    //$company = $html->find("span.rsltsubtitle", $i);
    $company = $html->find("div.resultdata a", $i);
    print $company . "\n";
    // deal with weird css from their website
    /*
    if( $company == "" || $company == 0 )
    {
        $company = $html->find("span.coname1 a", $i);
    }
        if ($results_number[$i] == ',') {
            // Skip the comma
            ++$i;
        }
        $final_result[$i] = $results_number[$i];
        ++$i;
    }
    $final_string = implode("", $final_result);
    echo "FINAL RESULT: " . $final_string . "\n";
    // Divide by 25, the number of results per page
    $number_of_pages = ceil($final_string / 25);
    echo "PAGE NUMBER: " . $number_of_pages . "\n";
    //  Will need to return the number of results instead
    return $number_of_pages;
}
$number_of_pages = GetTotalResults($total_results);
echo "char at now is: " . $char_at_now . "\n";
$my_url = "http://www.thomasnet.com/products/plastic-pipe-58530403-6.html";
$parts_of_page = BreakApartUrl($my_url);
// START MAIN LOOP FOR ALL PAGES
for ($j = 1; $j <= $number_of_pages; $j++) {
    $page = $parts_of_page[0] . "-" . $j . $parts_of_page[1];
    echo "THE PAGE IS: " . $page . "\n";
    // scrape page
    $html_content = scraperwiki::scrape($page);
    $html = str_get_html($html_content);
    //$html = $html->plaintext;
    // Example:  Displaying 126 to 150 out of 1,792 results
    $num_of_results = $html->find("div#rsltlbls", 0);
    $total_results = $num_of_results->plaintext;
    //------------