解决方法可以有以下几种:
from bs4 import BeautifulSoup
import requests
url = 'https://example.com'
response = requests.get(url)
html_content = response.text
soup = BeautifulSoup(html_content, 'html.parser')
tag_list = soup.find_all('tag_name') # 根据标签名称查找
tag_list = soup.select('css_selector') # 根据CSS选择器查找
if len(tag_list) > 0:
for tag in tag_list:
# 处理标签
else:
print("未找到匹配的标签")
通过逐步检查上述步骤,可以解决返回空字符串列表的问题。