How to extract contents of inner text of html tag?

Jason Friedman jsf80238 at gmail.com
Sat Mar 8 11:55:35 EST 2014


> for line in all_kbd:
>    if line.string == None:

I modified your code slightly:
for line in all_kbd:
    print(line)
    sys.exit()
    if line.string == None:

Running the new script yields:
$ python shibly.py
<kbd class="command">
    cp -v --remove-destination /usr/share/zoneinfo/
    <em class="replaceable"><code><xxx></xxx></code></em>
       \
    /etc/localtime
</kbd>

Meaning that
all_kbd=soup.find_all('kbd')

yields only a single string, not multiple strings as I'm guessing you expected.

You might also consider running your program as:

python -m pdb your_program.py



More information about the Python-list mailing list