error with parse function in lxml

后端 未结 3 675
[愿得一人]
[愿得一人] 2020-12-15 09:54

i have installed lxml2.2.2 on windows platform(i m using python version 2.6.5).i tried this simple command:

from lxml.html import parse 
p= parse(‘http://ww         


        
3条回答
  •  时光取名叫无心
    2020-12-15 10:36

    Since line breaks are not allowed in comments, here's my implementation of MattH's answer:

    from urllib2 import urlopen
    from lxml.html import parse
    
    site_url = ('http://www.google.com')
    
    try:
        page = parse(site_url).getroot()
    except IOError:
        page = parse(urlopen(site_url)).getroot()
    

提交回复
热议问题