Beautifulsoup使用 find_all()、select()从网页标签中提取子元素

例如先找到

class='info'的元素,继续在

内部获取元素内的文字:

p1=soup.find_all('p',class_='info')      

for each in p1:

      txtlist=each.find_all('span')

      for eachs  in txtlist:

             txtstr=eachs.string

或者:提取第一个p标签中第一个span元素内的文字

p2=soup.select('p.info')

txt=p2[0].select('span')[0].get_text()


#########
p3=soup.find_all('p',class_='info')
txt=p3[0].find('span').string 


你可能感兴趣的:(python)