【发布时间】:2020-12-06 11:41:14
【问题描述】:
我在获取href 标签时遇到问题,所以我的情况是这样的,
这是html 文件:
<div class="list-product with-sidebar">
<a class="frame-item" href="./produk-a.html" target="_blank" title="Produk A">
</a>
<a class="frame-item" href="./produk-b.html" target="_blank" title="Produk B">
</a>
</div>
这是我的代码
def get_category_item_list(category):
base_url = 'https://www.website.com/'
res = session.get(base_url+category)
res = BeautifulSoup(res.content, 'html.parser')
all_title = res.findAll('a', attrs={'class':'frame-item'})
data_titles = []
for title in all_title:
product_link = title.get('a')['href']
data_titles.append(product_link)
return data_titles
我想得到的是,href 链接.. 像这样
produk-a.html
produk-b.html
当我尝试运行它时.. 它不会让我在href 上获得链接,它们会给出错误代码:
TypeError: 'NoneType' object is not subscriptable
【问题讨论】:
标签: python html web-scraping beautifulsoup