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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation PHP DOM Scraping and Array Comparison problem

    After realizing that I can't do the scraping in JS yet, I decided to move on to PHP.

    PHP Code:
    <?php
    //$userurl = $_POST["link"];
    //$url = 'https://'.$userurl;
    $doc= new DOMDocument();
    $doc-> loadHTML('shibmax.x10host.com/grpbot/swearlist.html');
    $contents $doc->getElementByTagName('body')->item(0);
    $swear= Array("F**K","F**k","f**k","S**T","S**t","s**t","B**H","B***h","b***h");
    $pregDOM preg_split("/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" "[\s,]*'([^']+)'[\s,]*|" "[\s,]+/"$contents0PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE);
    $swearlist array_search($swear$pregDOMtrue);
    $intersect array_intersect($pregDOM$swear);
    echo(
    $intersect);
    echo(
    $swearlist);
    ?>
    Running the script displays a blank page. The HTML file linked contains swear words present in the $swear array.

    Error Reporting returned this :



    Fatal error: Call to undefined method DOMDocument::getElementByTagName() in /home/shibmaxx/public_html/grpbot/scanpage.php on line 6
    Note : I placed asterisks in the $swear array, 'cause I don't think that's allowed here. The actual script does not contain any asterisks for the array.

  2. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    7,766
    Thanks
    2
    Thanked 786 Times in 775 Posts
    The error is above the swear array as it is crashing in the line before that.

    I haven't used DOMDocument in PHP but if it is similar to JavaScript then you mistyped getElementsByTagName
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  3. Users who have thanked felgall for this post:

    Lancer26 (02-05-2016)

  4. #3
    New to the CF scene
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can't believe I missed that! lol. Thanks!


 

Tags for this Thread

Posting Permissions

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