2016-11-10 42 views
0

我在python 3.5中使用BeautifulSoup来解析html。虽然我可以从文件加载它,但是我需要从内存加载它,因为我从HTTP请求中获取它。我谷歌,但没有找到任何加载HTML从BeautifulSoup从内存。可能吗?BeautifulSoup的HTML - 从内存加载?

回答

0

如果您正在使用BeautifulSoup的4版本,尝试请求数据传递给它

from bs4 import BeautifulSoup 
import requests 

# replace the following URL 
response = requests.get("https://www.python.org") 
soup = BeautifulSoup(response.text,"html.parser") 
0
from BeautifulSoup import BeautifulSoup 
import requests 

data = requests.get('https://google.com').text 
soup = BeautifulSoup(data)