我可以如何结合使用Beautiful Soup和lxml解析器在网站中找到关键词?

2024-04-16 21:09:57 发布

您现在位置:Python中文网/ 问答频道 /正文

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结合使用,在网站主体中查找关键字? 注意,上面的代码可以工作,但是它没有使用我想要的解析器。你知道吗


Tags: 代码rehttp解析器maindefwwwcode