1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Super simple Php Crawler

Discussion in 'PHP' started by theblackjacker, Oct 17, 2009.

  1. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #21
    phpmyadmin will give you the correct syntax. Key length isn't required for TEXT fields.

    And the error is from indexing a text field.

     
    shallowink, Oct 19, 2009 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #22
    It will not only give a correct syntax, it will even create tables. So you don't need to write sql statements to create them manually.
     
    AsHinE, Oct 19, 2009 IP
  3. theblackjacker

    theblackjacker Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #23
    OK I fixed the text part in the database. The problem was that you can't use the text fields as an index like you can with a varchar.

    It still don't work though. I get the same problem with the text field as I get with the varchar.

    I echoed the links and the link that is the problem is the first link to use these symbols ''
    like this: 'http://example.com/example'

    The errorcode is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'http://www.e24.se/ego/startsidan_s189/http://bors.e24.se/bors24.se/site/overview' at line 1

    Anyone know a solution for this problem?
     
    theblackjacker, Oct 19, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #24
    As has been said, you need to mysql_real_escape_string() your sql variables.
     
    premiumscripts, Oct 19, 2009 IP
  5. theblackjacker

    theblackjacker Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #25
    I added this:
    mysql_real_escape_string($linkstring) or die(mysql_error());

    still getting the same errormessage: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'http://www.e24.se/ego/startsidan_s189/http://bors.e24.se/bors24.se/site/overview' at line 1

    I'm very close from throwing the computer out the window now..this thing just won't work..
     
    theblackjacker, Oct 19, 2009 IP
  6. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #26
    echo the entire sql and show it here.
     
    premiumscripts, Oct 19, 2009 IP
  7. john99

    john99 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #27
    thank you for posting
     
    john99, Oct 19, 2009 IP
  8. theblackjacker

    theblackjacker Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #28
    Ok I managed to get it to write to the database by changing the inserting code to this:

    $sql = "INSERT INTO testtable (`thetext`) VALUES ('" .mysql_real_escape_string($linkstring) ."')" ;

    mysql_query ( $sql ) or die(mysql_error());

    // a line of debug
    echo $sql ;

    Now the problem is that it puts all the links in the same row as one string. I thought it would recognice that they should be sepparated by the commas after converting the array to a string with the implode-function.

    I just need the program to know that each link should go in to a new row and then the database part should finally be solved:)
     
    theblackjacker, Oct 19, 2009 IP
  9. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #29
    1. Iterate over links.
    something like this:
    
    $links = $snoopy->results;
    foreach($links as $linkstring){
      $q = "INSERT INTO testtable SET `thetext` =' ".$linkstring." ' ";
      mysql_query($q);
    }
    
    PHP:
    OR

    2. modify $linkstring to insert several values;
    
    $linkstring = implode("','",$snoopy->results);
    $sql = "INSERT INTO testtable (`thetext`) VALUES ('" .$linkstring ."')" ;
    
    PHP:
    This is unsafe, but I suppose there are no bad symbols for sql in urls.
     
    AsHinE, Oct 19, 2009 IP
  10. cpollett

    cpollett Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #30
    I am teaching a class now where I wrote some crawler, page rank, and search code as part of the homework. I was interested in writing a crawler and search engine in PHP so I wouldn't have to deploy Tomcat to get Nutch running. The code is reasonably short and documented.

    http://www.cs.sjsu.edu/faculty/pollett/174.1.09f/?Hw4.shtml
     
    cpollett, Nov 5, 2009 IP
  11. ps3ubo

    ps3ubo Peon

    Messages:
    204
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #31
    Snoopy is madness lol, thing is it doesn't work on sites that I want it to work on, like to get the page source from megavideo video.. it gives 'fake' information for the user so it can't grab the download link xD
     
    ps3ubo, Nov 8, 2009 IP