Python:使用requests.get时无法打印Beautiful Soup

时间:2020-05-18 11:59:49

标签: python beautifulsoup

我正在尝试在Pycharm中运行以下代码,并且得到"Process finished with exit code 0",我猜测这意味着程序正在运行,但没有任何输出。我已经确保正确安装了beautifulsouprequestslxml。我不确定还有什么可能是错误的,主要是因为我从Corey schafer的视频中复制了它,并且对他来说还不错。

from bs4 import BeautifulSoup
import requests
source = requests.get('https://coreyms.com/').text
soup = BeautifulSoup(source, 'lxml')
print(soup.prettify())

2 个答案:

答案 0 :(得分:0)

安装html5lib

通过使用pip install html5lib

下载后,尝试以下代码:

soup = BeautifulSoup(source, 'html.parser')

答案 1 :(得分:0)

尝试使用此代码!

import requests
from bs4 import BeautifulSoup
page = requests.get('https://coreyms.com/')
soup = BeautifulSoup(page.content, 'html.parser')
print(soup.prettify())