python中html解析

import requests
from bs4 import BeautifulSoup

url = "..."

payload =...
headers = None

response = requests.request("POST", url, data=payload, headers=headers)

#print(response.text),type(response.text)
result=str(response.text)
soup=BeautifulSoup(result,"html.parser")
#print soup.body.string
a=soup.body.string.strip()
print a

错误处理:

init.py:166: UserWarning: No parser was explicitly specified

错误提示:To get rid of this warning, change this: BeautifulSoup([your markup]) 
to this: 
BeautifulSoup([your markup], “html.parsar”) 
markup_type=markup_type))

按照错误提示,将代码里的 BeautifulSoup([your_markup]) 在[your_markup]后面加上”html.parsar”即可 

猜你喜欢

转载自www.cnblogs.com/hanjiajiejie/p/9167846.html