import requests
from bs4 import BeautifulSoup
link = "http://www.santostang.com/"
headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}
r = requests.get(link, headers=headers)
soup = BeautifulSoup(r.text, "lxml")
title = soup.find("hl", class_="post-title").a.text.strip()
print(title)
这串代码用于提取目标网页第一篇文章的标题。我把代码放到PyCharm中运行,报错(AttributeError: 'NoneType' object has no attribute 'text');但代码在Python自带的IDLE中却能正常运行并输出结果。请问这是为什么?