国美金融贷款模块解析HTML,国美金融贷款支持网站链接
国美金融贷款通过使用BeautifulSoup模块对HTML文档进行解析,在命令行工具中进行安装。
1.bs4.BeautifulSoup()国美金融贷款函数能够处理HTTP网站上的URL requests.get()操作,并且还能处理本地存储的HTML文档。该功能可以通过调用open函数打开一个本地存储的HTML页面。
import requests, bs4
res = requests.get('http://i.firefoxchina.cn/?from=worldindex')
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text)
Warning (from warnings module):
File "C:\Users\King\AppData\Local\Programs\Python\Python36-32\lib\site-packages\beautifulsoup4-4.6.0-py3.6.egg\bs4\init.py", line 181
markup_type=markup_type))
警告信息:未明确指定解析器的情况
因此使用本系统中可选的最佳HTML解析器...原始设置中的"html.parser"。
通常不会有问题;但如果你在其他系统或不同的虚拟环境中运行代码...
The code that originated this warning is on the first line of the file
BeautifulSoup(YOUR_MARKUP})
to this:
BeautifulSoup(YOUR_MARKUP, "html.parser")
soup = bs4.BeautifulSoup(res.text, 'html.parser')
type(soup)
<class 'bs4.BeautifulSoup'>
我这里有错误提示,所以加了第二个参数。
import bs4
html = open('C:\ Users\ King\ Desktop\ 1.htm')
exampleSoup = bs4.BeautifulSoup(html)
exampleSoup = bs4.BeautifulSoup(html, 'html.parser')
type(exampleSoup)
<class 'bs4.BeautifulSoup'>
