python BeautifulSoup获取网页正文

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python BeautifulSoup获取网页正文相关的知识,希望对你有一定的参考价值。


通过BeautifulSoup库的get_text方法找到网页的正文:

#!/usr/bin/env python
#coding=utf-8

#html找出正文

import requests
from bs4 import BeautifulSoup

url=‘http://www.baidu.com‘
html=requests.get(url)

soup=BeautifulSoup(html.text)
print soup.get_text()

 

本文出自 “linux与网络那些事” 博客,请务必保留此出处http://khaozi.blog.51cto.com/952782/1793075

以上是关于python BeautifulSoup获取网页正文的主要内容,如果未能解决你的问题,请参考以下文章