Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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 如何获取嵌套元素?_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

Python 如何获取嵌套元素?

Python 如何获取嵌套元素?,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,html: 我使用以下代码: ['#41', '#42', '#43', '#44', '#45', '#46'] 但是这个代码被放在额外数据列表中 list = [] html = requests.get(value) soup = bs4.BeautifulSoup(html.text) num = soup.findAll('a', {'itemprop': 'replyToUrl'}) print(value , num, end='\n') list.append(num) li

html:

我使用以下代码:

['#41', '#42', '#43', '#44', '#45', '#46']
但是这个代码被放在额外数据列表中

list = []
html = requests.get(value)
soup = bs4.BeautifulSoup(html.text)
num = soup.findAll('a', {'itemprop': 'replyToUrl'})
print(value , num, end='\n')
list.append(num)
list = []
html = requests.get(value)
soup = bs4.BeautifulSoup(html.text)
num = soup.findAll('a', {'itemprop': 'replyToUrl'})
print(value , num, end='\n')
list.append(num)
>>> [a.text.strip() for a in soup.find_all('a', {'itemprop': 'replyToUrl'})]
[u'#41', u'#42', u'#43', u'#44', u'#45', u'#46', u'#47', u'#48', u'#49', u'#50']