Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python BeautifulSoup从HTML li标记中提取特定项_Python_Python 3.x - Fatal编程技术网

Python 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_

我想使用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_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(最后一次调用):