Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    scraping the data from website

    Hi guys,

    I really need your help, I have scraping the data from a website that i use to read the information on my php. I have a problem, I could not be able to scraping the right data from 5 hours backward of my current time, e.g my current time is 10pm and the 5 hours backward time is 5pm so i want to scrape the data that is on the same row as the 5pm time.

    here is the php code:

    PHP Code:
       <?php
        
        $data 
    file_get_contents('http://tvlistings.zap2it.com/tvlistings/ZCSGrid.do?stnNum=10179');
        
    preg_match_all('/<a id="rowTitle\d+" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im'$data$matches);
        
    $titles $matches[1];
        
        echo 
    $titles[19];
    I can only scraping the data that are 7 hours backward from my current time, but i can't be able to figure it out how i can scraping the data that are 5 hours backward from my current time.

    If you know how i can scraping the data in the same row as the time that are 5 hours backward from my current time, i would be very appreicated it if you could post the code that i can scraping the data that are 5 hours backward from my current time to the end of the page.

    Any advice would be much appreicated.

    Thanks in advance

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    How are you scraping data 7 hours backward? Can you show us how you are doing that?

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I am using the array to extract the data, but it is not the right data that i want to extract it.

    Here is the one I use to extract the data using with an array:

    Code:
    echo $titles[19];

    If I change from 19 to 21, i will get the right data 5 hours behind my current time, but the array will change on later on and the data won't be the right one.

    Any idea?

  • #4
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    just parse HTML and you will have verything you want to have
    http://php.net/manual/en/book.dom.php

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by deeper65 View Post
    you need to make $titles an array. use a loop and add inside the loop-> preg_match_all('/<a id="rowTitle\d+" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im', $data, $matches); $titles[$i]= $matches[1] end the loop.
    thanks for your help, but i am getting an fatal error. The error I am getting is:

    Fatal error: Call to undefined function reg_match_all() in /home/mark103/public_html/scrape.php on line 4


    here is the php code:

    PHP Code:
    <?php

    $data 
    file_get_contents('http://tvlistings.zap2it.com/tvlistings/ZCSGrid.do?stnNum=10179');
    reg_match_all('/<a id="rowTitle\d+" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im'$data$matches); 
    $titles[$i]= $matches[1];

    echo 
    $titles[19];
    ?>
    do you know why i get the error and could you help me to fix it?

  • #6
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    I haven't even read the question, but for the error, you have reg_match_all() in your code instead of preg_match_all().

    PHP Code:
    <?php
    $data 
    file_get_contents('http://tvlistings.zap2it.com/tvlistings/ZCSGrid.do?stnNum=10179');

    //Make correction below
    preg_match_all('/<a id="rowTitle\d+" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im'$data$matches); 
    $titles[$i]= $matches[1];

    echo 
    $titles[19];
    ?>

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I'm going to jump in here without any scripting to show ... no spare time today.

    He knows the difference is always 5 hours. Is this something where the time for each show can be compared to his local current time by using some strtotime functions?

    Look at the array from the beginning ... each line would be checked with the time of the show (less the 5 hours) is equal to his time. This will find the current show and then loop ahead from there, displaying his hours instead of theirs.

    In fact, if anyone using his script knows the difference in hours between tvlistings.zapit and their own local time, the results would always be correct for whoever is viewing it.

    Sorry again ... I'm just thinking out loud.

  • #8
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No, I want to scrape the programme title that is in current time in the USA, for e.g. the usa time is 10pm while my current time is 3am.

    Here is the example programme that showing on right now:

    PHP Code:
     10:00 PM Baseball Tonight

        LIVE

    11
    :00 PM SportsCenter

        LIVE

    Tomorrow
    12
    :00 AM SportsCenter

        LIVE

    1
    :00 AM SportsCenter

        LIVE

    2
    :00 AM SportsCenter

        LIVE

    3
    :00 AM SportsCenter

    4
    :00 AM SportsCenter 
    I hope you get my point?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •