【发布时间】:2021-12-13 01:57:54
【问题描述】:
所以我尝试使用以下代码从 href 属性与模式 /how-to-use/[a-zA-Z]+ 匹配的网站中抓取所有标签
代码在这里:
import requests
from bs4 import BeautifulSoup
import re
webpage = requests.get('https://www.talkenglish.com/vocabulary/top-1500-nouns.aspx').content
soup = BeautifulSoup(webpage, "html.parser")
def has_how_to_use(tag):
pattern = re.compile('\/how-to-use\/[a-zA-Z]+')
return bool(re.search(pattern, tag.attr('href')))
word_list = soup.find_all(has_how_to_use)
但我不断收到关于无法调用 NoneType 对象的错误,我只是不确定哪个位正在评估为 NoneType 对象
【问题讨论】:
标签: python regex web-scraping beautifulsoup