Python BeautifulSoup从HTML li标记中提取特定项
我想使用BeautifulSoup从HTML li标记中提取特定项。我在程序的这一部分中发现了一个错误,导致程序停止:Python BeautifulSoup从HTML li标记中提取特定项,python,python-3.x,Python,Python 3.x,我想使用BeautifulSoup从HTML li标记中提取特定项。我在程序的这一部分中发现了一个错误,导致程序停止: product_url = 'https://example.com/product' page = sess.get(product_url) page = BeautifulSoup(page.text) list = page.select('li.items') list_items = [ { "menu_
product_url = 'https://example.com/product'
page = sess.get(product_url)
page = BeautifulSoup(page.text)
list = page.select('li.items')
list_items = [
{
"menu_name": menu.find('h3').text,
"menu_type": menu.find('strong').text.strip(),
"menu_level": menu.select('.list_item')[0].text.strip() if menu.select('.list_item') else '' ,
"menu_url": BASE_URL + menu.select('a.title')[0]['href'],
}
for menu in list]
#Any code after this line not worked
此外,如何在对象内部打印字符串以进行调试?此处的错误是什么,以及
打印列表
givescan您共享从中提取数据的html文件部分?@YasinYousif Traceback(最后一次调用):