Beautiful Soup

From ElectroDragon Wiki

属性

案例 marketwatch =》 https://www.marketwatch.com/investing/stock/aapl

  • 查找属性 = print(soup.find_all(field='last'))
<bg-quote class="ignore-color negative" field="last" format="0,0.00" channel="/zigman2/quotes/211618636/realtime" data-last-stamp="1567363673000" data-last-raw="3075.54">3,075.54</bg-quote>
  • second
print(soup.find_all(channel="/zigman2/quotes/202934861/composite,/zigman2/quotes/202934861/lastsale")[1].string)

Find

 <th scope="col" id="DetailTilte">
 <h1>微博客信息服务管理规定</h1>
 </th>
  • title = bs.find('th', id='DetailTilte').h1.get_text()
  • demo = soup.find ('h3', attrs = {'class': "intraday__price"} )
<div class="last_price"><p>$41.31 <span>USD</span></p></div>
  • e = soup.find('div', class_="last_price").find('p').text >>> $41.31 USD
  • e = soup.find('div', class_="last_price").find('p').contents >>> ['$41.31 ', USD]