[Tutor] Writing data to JSON Help
Peter Otten
__peter__ at web.de
Sat Dec 16 08:57:44 EST 2017
Mats Wichmann wrote:
> also, has_key is no longer favored in the Python world (that is not what
> is wrong with your code).
But then the beautiful soup is a world on its own:
$ python3
Python 3.4.3 (default, Nov 28 2017, 16:41:13)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup as BS
>>> soup = BS("""<html><body><a
href="foo">with</a><a>without</a></body></html>""")
>>> [a for a in soup.find_all("a") if "href" in a]
[]
>>> [a for a in soup.find_all("a") if a.has_key("href")]
/usr/lib/python3/dist-packages/bs4/element.py:1400: UserWarning: has_key is
deprecated. Use has_attr("href") instead.
key))
[<a href="foo">with</a>]
At least they seem to be moving in the right direction.
More information about the Tutor
mailing list