I am able to fetch the text in td element by BeautifulSoup. However, this includes characters that I don't want. I just want the numbers, how can I remove the characters?
The code looks like this:
import requests
import pandas as pd
from bs4 import BeautifulSoup
record = []
hksi = ['CKH']
url = "http://www.etnet.com.hk/www/tc/futures/futures_stockoptions.php?atscode={}&month=202101"
for s in hksi:
response = requests.get(url.format(s))
info = response.text
soup = BeautifulSoup(info, "lxml")
bid = soup.find('td', {'style': 'padding:10px 0 5px 10px; border-top:1px dotted #e2e2e2; font-weight:bold;'}).text
ratio = soup.find('td', {'style': 'padding:10px 0 5px 0; border-top:1px dotted #e2e2e2; font-weight:bold;'}).text
ask = soup.find('td', {'style': 'padding:10px 10px 5px 0; border-top:1px dotted #e2e2e2; font-weight:bold;'}).text
record.append({
'symbol' : s,
'bid' : bid,
'ask' : ask,
'ratio': ratio
})
print(bid)
Output:
認購總數 1441
I want to remove the "認購總數", and the output should look like this:
1441