1. python bs4 是个什么
这是一个模块,要通过如下语句安装:
pip install bs4
2. 关于python bs4的import问题
1.谁说没BeautifulSoup的 。。。你打开
__init__.py里面有个class 就是BeautifulSoup
2.可以。这样不是管理很乱么。。
直接把源代码放到 Python27\Lib\site-packages目录下就行了
3. python中关于bs4获取链接的问题
import urllib2
import urllib
from lxml import etree
def tieba_spider(fullurl):
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
}
request = urllib2.Request(fullurl,headers = headers)
html = urllib2.urlopen(request).read()
4. python bs4分析html时,怎么找到最底层的某个标签
frombs4importBeautifulSoup
of=open(r'test.html','r')
html_doc=of.readlines()
of.close()
soup=BeautifulSoup(' '.join(html_doc),'html.parser')
printsoup.body.p
<!DOCTYPEhtml>
<html>
<head>
<title>test</title>
</head>
<body>
<p>
<b>xxxxxxxxx</b>
</p>
<b>
<ahref="aasdfd"></a>
<ahref="aasdfd"></a>
</b>
</body>
</html>
5. from bs4 import BeautifulSoup在python3用什么替代了
不变,仍用 from bs4 import BeautifulSoup
如果没有安装bs4,需要在命令行工具中使用pip命令进行安装,pip install bs4
6. python中bs4.beautiful解析有时候不加前边的bs4 有什么区别
这个就是看你是如何import包的
如果是import bs4,那么就应该是bs4.BeautifulSoup
如果是from bs4 import BeautifulSoup,就可以直接使用BeautifulSoup