1

I am sending an HTML text from PHP to Python via STDIN. My objctive is to use Aaron Swartz's script "html2text.py" and to print the result to PHP via STDOUT.

Camarade Jan gave me the word and put me in the right direction. Here's my test:

PHP code:

$t='<p><b>Hello</b><i>world!</i></p>';
$scaped=preg_quote($t,"/")."\n";//\<p\>\<b\>Hello\<\/b\>\<i\>world\!\<\/i\>\<\/p\>
exec('python hi.py '.$scaped,$r);
print_r($r);//result

Python code:

#! /usr/bin/env python
import html2text
import sys
#print html2text.html2text(sys.stdin.read()) #this part of the code didn't work out...
print html2text.html2text(sys.argv[1])

Result:

Array
(
    [0] => **Hello**_world!_
    [1] => 
    [2] => 
)

All the files are in the same directory (under chmod 077). I am using Aaron Swartz's html2text.py version 2.39 and also installed "python-html2text.noarch" on my Fedora 14 (though I couldn't make it work with this last one).

1
  • Can you also add the command line you are using? Commented Jan 14, 2011 at 0:32

1 Answer 1

2

You're just passing the last line to html2text , and you are not using html2text correctly do this instead :

import html2text
import sys

print html2text.html2text(sys.stdin.read())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.