简体   繁体   中英

how to scrape value using id in beautiful soup

I want to store the text of value in a variable status
which is either Discharging or Charging

<input id="batterystatus" value="Discharging" type="hidden">

I have tried to store text in status

site="http://jiofi.local.html/"
opener=uo(site)
page=opener.read()
opener.close()
parser = bs(page, "html.parser")
status=parser.find(id='batterystatus') 

尝试这个。

Print(status['value'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM