www.webdeveloper.com
Results 1 to 7 of 7

Thread: scraping the data from website

  1. #1
    Join Date
    Sep 2008
    Posts
    62

    scraping the data from website

    Hi,

    I am having a problem with scraping the data from the website. I can't be able to output the data to my php after I have scraping the data from the website. On my php it show as a empty page.

    here is the html source I want to scrape:

    Code:
    <span id="row3Time" class="zc-ssl-pg-time">11:00 AM</span>
    <a id="rowTitle3" class="zc-ssl-pg-title" href='http://tvlistings.zap2it.com/tv/sportscenter/EP00019917'>SportsCenter</a>
    <ul class="zc-icons">
    <li class="zc-ic zc-ic-span"><span class="zc-ic-live">LIVE</span></li></ul>
    </li>
    <li class="zc-ssl-pg" id="row1-4" style="">
    
    <span id="row4Time" class="zc-ssl-pg-time">12:00 PM</span>
    <a id="rowTitle4" class="zc-ssl-pg-title" href='http://tvlistings.zap2it.com/tv/sportscenter/EP00019917'>SportsCenter</a>
    <ul class="zc-icons">
    <li class="zc-ic zc-ic-span"><span class="zc-ic-live">LIVE</span></li></ul>
    </li>
    <li class="zc-ssl-pg" id="row1-5" style="">
    
    <span id="row5Time" class="zc-ssl-pg-time">1:00 PM</span>
    <a id="rowTitle5" class="zc-ssl-pg-title" href='http://tvlistings.zap2it.com/tv/sportscenter/EP00019917'>SportsCenter</a>
    <ul class="zc-icons">
    <li class="zc-ic zc-ic-span"><span class="zc-ic-live">LIVE</span></li></ul>
    here is the php source:

    PHP Code:

    <?php

    $contents 
    file_get_contents('http://tvlistings.zap2it.com/tvlistings/ZCSGrid.do?stnNum=10179');
    preg_match('/<a id="rowTitle3" class="zc-ssl-pg-title"[.*]<\/a>/i'$data$matches);
    $rowtitle $matches[1];
    echo 
    $rowtitle."<br>\n";
    ?>
    And here is the php output:
    PHP Code:
    <br
    does anyone know how I can scraping the data from that website using with <a id=rowTitle3 to the end of the page?

    any advice would be much appreicated.

    Thanks in advance
    Last edited by mark107; 04-15-2013 at 09:53 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,528
    Have you confirmed that $contents actually contains the expected HTML text?

    Also, you may find the DOM extension to be a more robust way to grab data than preg functions.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2008
    Posts
    62
    yeah I am confirmed that $contents actually contains in the expected HTML text. But I am looking for to match the data before ouput them in my php.


    Could you please post the source for variable that I am looking for to match the data and then to output them to my php?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,528
    PHP Code:
    '/<a id="rowTitle3".*/is' // "s" modifier makes "." include newlines 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Sep 2008
    Posts
    62
    Thank you for your help. I have got a problem with scraping the data from a website that I use to output the data in my php. It did not scraping the correct data in a correct time, e.g my local time is 10:00pm and the current time of the tv programme is 5:00pm. I can only scraping the data that is outside of the current time of tv programme like 3:00pm.

    here is the php:

    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];
        
    ?>

    Do you know how I can scraping the data from the tv programme website in a current time, e.g my local time is 10:00pm and the tv programme time is 5:00pm??

  6. #6
    Join Date
    Apr 2013
    Posts
    2
    It is fun and bring a lot of useful things for me.thank you for sharing

  7. #7
    Join Date
    Sep 2008
    Posts
    62
    what the hell are you talking about?

    Trolling on my thread?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles