Finding multiple attributes within the span tag in Python

后端 未结 2 628
感动是毒
感动是毒 2020-12-10 05:46

There are two values that i am looking to scrape from a website. These are present in the following tags:

4.1
&         


        
2条回答
  •  天命终不由人
    2020-12-10 06:02

    Probably there is a better way, but it is eluding me at present. It can be done with css selectors like this:

    html = '''4.1
              2.9
              22'''
    
    soup = bs4.BeautifulSoup(html)
    
    selectors = ['span.sp.starBig', 'span.sp.starGryB']
    result = []
    for s in selectors:
        result.extend(soup.select(s))
    

提交回复
热议问题