2016-11-10 33 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)