Page scraping

Discussion in 'PHP' started by Egnited, Jun 17, 2008.

  1. #1
    Egnited, Jun 17, 2008 IP
  2. myhart

    myhart Peon

    Messages:
    228
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You might try something like the following. It seems to work ok but can probably be inproved on!

    <?
    $weather = file_get_contents('http://mobile.weather.gov/port_mp_ns.php?select=1&CityName=Wichita&site=ICT&State=KS&warnzone=KSZ083');
    
    $weather = strstr("$weather","</div>");
    preg_match_all('/<b>(.*)<br>/', $weather, $forecast);
    $count = count($forecast[1]);
    for ($row = 0; $row < $count ; $row++) {
    echo "<b>".$forecast[1]["$row"]."<br>";
    }
    ?>
    PHP:
     
    myhart, Jun 18, 2008 IP
  3. myhart

    myhart Peon

    Messages:
    228
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just noticed that you also wanted time and date. Don't have time to add that now. But will see what I can do soon.
     
    myhart, Jun 18, 2008 IP
  4. myhart

    myhart Peon

    Messages:
    228
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hopefully this will do what you need? Time and date are now included.

    <?
    $weather = file_get_contents('http://mobile.weather.gov/port_mp_ns.php?select=1&CityName=Wichita&site=ICT&State=KS&warnzone=KSZ083');
    preg_match_all('/Last Update:<\/b><br>(.*)<hr>/', $weather, $update);
    $weather = strstr("$weather","</div>");
    preg_match_all('/<b>(.*)<br>/', $weather, $forecast);
    echo "<b>Last Update:</b> " .$update[1][0];
    echo "<br><br>";
    $count = count($forecast[1]);
    for ($row = 0; $row < $count ; $row++) {
    echo "<b>".$forecast[1]["$row"]."<br>";
    }
    ?>
    PHP:
     
    myhart, Jun 18, 2008 IP
    Rapidrobert likes this.