python - "soup.prettify()" gives just URL -
i'm using python3, beautifulsoup4
when run code below, gives url "www.google.com" not xml. couldn't find wrong.
from bs4 import beautifulsoup import urllib html = "www.google.com" soup = beautifulsoup(html) print (soup.prettify())
you need use urllib2 or similar library fetch html
import urllib2 html = urllib2.urlopen("www.google.com") soup = beautifulsoup(html) print (soup.prettify())
edit: side note clarify why suggested urllib2. if read urllib documentation, you'll find "the urlopen() function has been removed in python 3 in favor of urllib2.urlopen()." given have tagged python3, urllib2 best option.
Comments
Post a Comment