Python 如何获取嵌套元素?
html: 我使用以下代码: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
['#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']