要解决这个问题,我们需要检查以下几个方面:
pip install beautifulsoup4
from bs4 import BeautifulSoup
import requests
url = "https://www.sainsburys.co.uk/"
response = requests.get(url)
html_content = response.content
soup = BeautifulSoup(html_content, 'html.parser')
element = soup.find('element_name', attrs={'attribute_name': 'attribute_value'})
if element is not None:
# 执行操作
else:
print("Beautiful Soup从Sainsbury's返回了None。")
综上所述,以下是一个示例代码,演示了如何检查Beautiful Soup是否从Sainsbury's返回了None:
from bs4 import BeautifulSoup
import requests
url = "https://www.sainsburys.co.uk/"
response = requests.get(url)
html_content = response.content
soup = BeautifulSoup(html_content, 'html.parser')
element = soup.find('element_name', attrs={'attribute_name': 'attribute_value'})
if element is not None:
# 执行操作
else:
print("Beautiful Soup从Sainsbury's返回了None。")
请注意,示例代码中的 'element_name' 和 'attribute_name' 是需要根据您要查找的具体元素进行替换的。