繁体   English   中英

如何将Beautiful汤和lxml Parser结合使用以在网站中找到关键字?

[英]How can I use Beautiful soup in combination with lxml Parser to find a keyword in a website?

def main():


  openurl = urllib2.urlopen("http://www.pythonforbeginners.com")
    content = openurl.read()
    code = openurl.code

    soup = BeautifulSoup(content) #I think I need to change something here!!
    print soup
    if soup.body.find(text=re.compile('python', re.IGNORECASE)):
      print "i think it's working"
    openurl.close()

如何修改此代码,以允许我将lxml解析器与Beautiful Soup结合使用以在网站正文中找到关键字? 请注意,上面的代码有效,但是它没有使用我想要的解析器。

要将lxml用作解析器,请提供“ lxml”作为第二个参数。

soup = BeautifulSoup(content, 'lxml')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM