Code Monkey home page Code Monkey logo

php-simple-html-dom-parser's Introduction

php-simple-html-dom-parser

Version 1.9.1 - PHP 7.3 compatible PHP Simple HTML DOM Parser changelog: https://sourceforge.net/projects/simplehtmldom/files/simplehtmldom/1.9.1/

Install

composer require kub-at/php-simple-html-dom-parser

Usage

use KubAT\PhpSimple\HtmlDomParser;

...
$dom = HtmlDomParser::str_get_html( $str );
or
$dom = HtmlDomParser::file_get_html( $file_name );

$elems = $dom->find($elem_name);
...

php-simple-html-dom-parser's People

Contributors

kub-at avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-simple-html-dom-parser's Issues

Maximum execution time of 60 seconds exceeded in simple_html_dom.php on line 146

I have a similar problem as it is described in:

Would you take a look into it? It looks like it happened only in some specific PHP version.

Error:

PS C:\projects\kentico-cloud-sample-app-php> php artisan serve
Laravel development server started: <http://127.0.0.1:8000>
[Tue Sep 17 15:42:21 2019] PHP Fatal error:  Maximum execution time of 60 seconds exceeded in C:\projects\kentico-cloud-sample-app-php\vendor\kub-at\php-simple-html-dom-parser\src\KubAT\PhpSimple\lib\simple_html_dom.php on line 146
[Tue Sep 17 15:42:21 2019] PHP Stack trace:
[Tue Sep 17 15:42:21 2019] PHP   1. simple_html_dom\simple_html_dom_node->__destruct() C:\projects\kentico-cloud-sample-app-php\vendor\kub-at\php-simple-html-dom-parser\src\KubAT\PhpSimple\lib\simple_html_dom.php:0
[Tue Sep 17 15:43:52 2019] PHP Fatal error:  Maximum execution time of 60 seconds exceeded in C:\projects\kentico-cloud-sample-app-php\vendor\kub-at\php-simple-html-dom-parser\src\KubAT\PhpSimple\lib\simple_html_dom.php on line 146
[Tue Sep 17 15:43:52 2019] PHP Stack trace:
[Tue Sep 17 15:43:52 2019] PHP   1. simple_html_dom\simple_html_dom_node->__destruct() C:\projects\kentico-cloud-sample-app-php\vendor\kub-at\php-simple-html-dom-parser\src\KubAT\PhpSimple\lib\simple_html_dom.php:0
[Tue Sep 17 15:44:52 2019] PHP Fatal error:  Maximum execution time of 60 seconds exceeded in C:\projects\kentico-cloud-sample-app-php\vendor\kub-at\php-simple-html-dom-parser\src\KubAT\PhpSimple\lib\simple_html_dom.php on line 146
[Tue Sep 17 15:44:52 2019] PHP Stack trace:
[Tue Sep 17 15:44:52 2019] PHP   1. simple_html_dom\simple_html_dom_node->__destruct() C:\projects\kentico-cloud-sample-app-php\vendor\kub-at\php-simple-html-dom-parser\src\KubAT\PhpSimple\lib\simple_html_dom.php:0
[Tue Sep 17 15:44:53 2019] 127.0.0.1:55071 [200]: /favicon.ico

Repro steps

  • Clone https://github.com/Simply007/kentico-cloud-sample-app-php.git
  • open desctructissue
  • run composer update
  • run php artisan serve
    ** Error is shown

Class not found

Hello! I installed the library via composer and then connected it using autoload to my router. Next, I tried to use it in the file where I add articles to the site, but I got:


Fatal error: Uncaught Error: Class "simple_html_dom\simple_html_dom" not found in C:\OSPanel\domains\localhost\php\classes\Blog.php:15
Stack trace:
#0 C:\OSPanel\domains\localhost\router.php(29): classes\Blog::handlerAddArticle()
#1 C:\OSPanel\domains\localhost\php\classes\Route.php(24): {closure}()
#2 C:\OSPanel\domains\localhost\router.php(29): Route::post()
#3 {main}
thrown in C:\OSPanel\domains\localhost\php\classes\Blog.php on line 15

The file where I add the article:

namespace classes;
use simple_html_dom\simple_html_dom;

class Blog
{
public static function handlerAddArticle()
{
global $mysqli;
$title = $_POST['title'];
$content = $_POST['content'];
$author = $_SESSION['login'];
$html = new simple_html_dom();
$html->load($content);
var_dump($html);
$img = $html->getElementByTagName('img');
$meta = explode(',', $img->src)[0];
$base64 = explode(',', $img->src)[1];
$extension = explode(';', explode('/', $meta)[1])[0];
$filename = "img/blog/" . microtime() . "." . $extension;
$ifp = fopen($filename, 'wb');
fwrite($ifp, base64_decode($base64));
fclose($ifp);
$img->src = "/" . $filename;
$content = $html->save();

    switch (true) {
        case(empty($title) && empty($content)):
            return json_encode(['result' => 'error']);
        case(empty($title)):
            return json_encode(['result' => 'errorTitle']);
        case(empty($content)):
            return json_encode(['result' => 'errorText']);
        default:
            $mysqli->query("INSERT INTO articles(title, content, author) VALUES ('$title', '$content', '$author')");
            return json_encode(['result' => 'success']);
    }
}

Call to a member function find() on bool

I'm using this package to parse 2 HTML pages which I suppose are identical in structure.

$firstPageHTML = 'https://controlc.com/bfa5ec9a'
$secondPageHTML = 'https://controlc.com/e8188d3e'

$parser = HtmlDomParser::str_get_html($secondPageHTML);

It seems that when I try to parse the second page HTML, HtmlDomParser's str_get_html method doesn't log anything. Eventually I get the following error:

Call to a member function find() on bool
$tableLength = count($parser->find('div[id="content"] table[class="tabelcalorii"] tr')) - 2;

What could be the issue here? $firstPageHTML works fine, using the latest version of the package

LE: increasing MAX_FILE_SIZE within simple_html_dom.php seems to fix the issue.

set MAX_FILE_SIZE

Hi, i got problem when reading site that has large html code. I found out that you can set the MAX_FILE_SIZE. Now i change it directly in vendors folder and i can read the site again. Can you make a config file that i can set in app/config/

Thank you,.

"Creation of dynamic property" warning in PHP 8.2

I get:

Deprecated: Creation of dynamic property simple_html_dom\simple_html_dom::$optional_closing_array is deprecated in /home/rosell/github/dom-util-for-webp/vendor/kub-at/php-simple-html-dom-parser/src/KubAT/PhpSimple/lib/simple_html_dom.php on line 1489

From PHP 8.2, properties needs to be defined before used.
In PHP 8.2, a warning is triggered. In PHP 9.0, an error will be thrown

See: https://wiki.php.net/rfc/deprecate_dynamic_properties

I'm aware that this should be fixed in the original simple_html_dom.php, but until then, I propose that it is fixed here.

Noise in script tag

When attempting to parse all Heading tags of certain sites, there's an opening Heading tag in script data, and forceTagsClosed doesn't seem to apply.

How to avoid this H tag parsing in the script tag?

Example site: techcrunch dot com with H2 wrapped in script tags.

find('H2') for the above site example collects garbage.

Amazing script, btw! Please advise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.