-1

I need to scrape text in span class and I only want to store the text information I need.

Please see the HTML example below:

<div class="row">
   <div class="col-md-2">
      <span id="plcMain_lblBandNumber" class="control-label" style="font-weight: bold;">Number</span>
   </div>
   <div class="col-md-10">
      <span id="plcMain_txtBandNumber" class="control-label">626</span>
   </div>
</div>
<br />

The only text I need from the above HTML is 626.

Below is my python code:

import requests
from bs4 import BeautifulSoup

URL = "Link"
Page = requests.get(URL)

soup = BeautifulSoup(page.content,'html.parser')

results = soup.find(id = 'plcMain_textBandNumber')

print(results)

The result I got from the print statement is the HTML text below:

enter image description here

But I only want it to return the value of 626.

Leanne
  • 3
  • 2

2 Answers2

0

If you want to get text you should add to end text

results = soup.find(id = 'plcMain_textBandNumber').text
dimay
  • 2,768
  • 1
  • 13
  • 22
0

You have to fetch text like this

results = soup.find(id = 'plcMain_textBandNumber').getText()
Shahid
  • 60
  • 11