GithubHelp home page GithubHelp logo

Comments (6)

soundasleep avatar soundasleep commented on August 26, 2024

It sounds like it's loading a different DTD (XHTML instead of HTML5 or something) or encoding. Could you post the HTML file you're trying to translate? Perhaps you can try minimise the HTML file to the smallest file that creates these errors?

from html2text.

feelsickened avatar feelsickened commented on August 26, 2024

Thanks for the prompt response - The HTML was from this article: http://www.smh.com.au/digital-life/computers/gadgets-on-the-go/getflix-offers-the-best-of-both-worlds-20150406-1mf3aa.html
What I did encoding wise - and what I did before putting that article into HTML2TEXT - I'll shed light on momentarily for you.

from html2text.

feelsickened avatar feelsickened commented on August 26, 2024

Very sorry for delay in providing proper issue details to you.

I am running the following:
$article_URL = (example provided above) http://www.smh.com.au/digital-life/computers/gadgets-on-the-go/getflix-offers-the-best-of-both-worlds-20150406-1mf3aa.html
$webpage_html_object = new DOMDocument();
$webpage_html_object->loadHTMLFile($article_URL);
$body = $webpage_html_object->getElementsByTagName('body');
if ( $body && 0<$body->length ) {
$body = $body->item(0);
$webpage_body_html_string = $webpage_html_object->savehtml();
}
Then:
$as_plaintext = convert_html_to_text($webpage_body_html_string);

At one time I used, but have since commented out this line in preference of the above:
$webpage_body_html_string = $webpage_html_object->savehtml($body);

from html2text.

soundasleep avatar soundasleep commented on August 26, 2024

It looks like the HTML is invalid, so similar to issue #10. Maybe we can look at adding an option to ignore invalid HTML warnings...

What happens if you parse the HTML directly?

$as_plaintext = convert_html_to_text(file_get_contents("http://www.smh.com.au/digital-life/computers/gadgets-on-the-go/getflix-offers-the-best-of-both-worlds-20150406-1mf3aa.html"));

from html2text.

feelsickened avatar feelsickened commented on August 26, 2024

okay trying that returns more issues:
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 151 in /home/content/20/10935220/html/engineroom/assets/src/Html2Text.php on line 40

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 154 in /home/content/20/10935220/html/engineroom/assets/src/Html2Text.php on line 40

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 157 in /home/content/20/10935220/html/engineroom/assets/src/Html2Text.php on line 40

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 160 in /home/content/20/10935220/html/engineroom/assets/src/Html2Text.php on line 40

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 166 in /home/content/20/10935220/html/engineroom/assets/src/Html2Text.php on line 40

I don't have any problems with a slightly older version of your html2text script -

from html2text.

twogood avatar twogood commented on August 26, 2024

If you have invalid HTML I recommend running it through Tidy first.

from html2text.

Related Issues (20)

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.