Results 1 to 4 of 4

Thread: Dynamically 'Grabbing' Content

  1. #1
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamically 'Grabbing' Content

    I was just wondering, how exactly do you grab content from another site?

    ie.
    A sports page (website A) has tables setup with stats on teams.
    My page (website B) will have empty tables setup.

    How do I grab the info from site A and put it into site B? I would like to use purely PHP... I know it is possible, but I can not remember how, nor can I find a tutorial on the subject.

    Any help would be greatly appreciated!

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    If site A has it's information stored in a database then it is easy with php,

    if it's just a static page then I don't know if it's possible, probably not.

    You could maybe use an iframe to include the whole page but i doubt you can extract info from table cells directly.

  3. #3
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The site uses a database, but I don't have access to it directly...(ie. login information). How were you implying I go about doing this?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You can get the content of a page using various functions, probably file_get_contents().
    Then parse that string as you want.
    You can use a marker to find a certain item.
    For example, substr($html,strpos($html,'<username>')) would return the html from the page starting at the location of the "username" tag (example; obviously invalid).

    1. Code is needed to determine how it will split this. Using substr(), str_replace(), strpos() and other functions would work, or you could learn regex (regular expressions) which are basically a way to use complex wildcards (like * in some search engines) to find, for example the text between 'a' and 'b', etc. They're harder, but more efficient.

    2. Specifically, though, you will need to find exactly what determines the data you want. Is it always after a certain tag [ex: '<b>']? Is it after a certain instance of a certain tag [ex: the <b> tag after the text 'names']? Something more complex [the b tag after the word names if the page has names, otherwise it's after the third <p> tag, or it's the title of the page... etc]?

    Or you could use an iframe.

    Or you could ask permission to the data and find out how to connect. That's the best option. Using data without permission is illegal and there's no way around that. An iframe is a very gray area, leaning toward ok, but actually taking data and claiming it as your own is not; crediting them when doing so is more complex, but still is their right to refuse your use.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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