繁体   English   中英

为什么 BeautifulSoup 4 在控制台中没有返回?

[英]Why BeautifulSoup 4 returns none in console?

from bs4 import BeautifulSoup
import requests

response = requests.get(url="https://news.ycombinator.com/news")
yc_web_page = response.text

soup = BeautifulSoup(yc_web_page, "html.parser")
print(soup.title)

当我尝试运行此代码时,我在控制台中得到了这个。

None

我刚刚添加了response.ok并且它起作用了。 这是完整的代码:

from bs4 import BeautifulSoup
import requests

response = requests.get(url="https://news.ycombinator.com/news")
response.ok
yc_web_page = response.text

soup = BeautifulSoup(yc_web_page, "html.parser")

print(soup.title)

我在控制台中得到<title>Hacker News</title> 所以是的,它确实有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM