How do you scape part of web pages using regex

Discussion in 'PHP' started by Andreajr, Dec 18, 2008.

  1. #1
    How do u scrape part of web pages using regex I know I know there is google but I can find it. How do you scape parts of web pages like google trends.
     
    Andreajr, Dec 18, 2008 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    google trends can be scaped with php by fetching their rss feed, you wont need regex for that
     
    crivion, Dec 19, 2008 IP
  3. caribbean_hatch

    caribbean_hatch Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you DO want to scrape, you need to look for unique patterns in the data/tags and parse it out - something along the lines of:

    if this case the function is loading the whole page first, so you don't want to have this live on your site, but have it dump just the data itself to a file (using a cron job if need be), and then just read the data file into your site.
    :cool:
     
    caribbean_hatch, Dec 19, 2008 IP
  4. herbacious

    herbacious Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i prefer using greedy modifier like this
    i also recommend using a different delimiter to the traditional forward slash - not very helpful when parsing html.

    $pattern = '%<h1 class="title">(.+?)</h1>%';
    preg_match($pattern, $html, $matches);
    $title = $matches[1];
     
    herbacious, Dec 19, 2008 IP
  5. Andreajr

    Andreajr Peon

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It the same way? and whats a greedy modifier?
     
    Andreajr, Dec 19, 2008 IP
  6. caribbean_hatch

    caribbean_hatch Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks, that makes more sense herby...

    (He means a modifier that grabs it all - whatever's between the tags...)
     
    caribbean_hatch, Dec 20, 2008 IP
  7. Andreajr

    Andreajr Peon

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    kk thanks it does make more sense.
     
    Andreajr, Dec 20, 2008 IP