'"None" value for getting text from HTML span tags
Using Beautiful soup, I'm trying to get text from a span tag that's in a td tag, that's in a tr tag, that's inside a table tag inside a form tag in the body of a webpage. The text is Request for Quotation (RFQ).
The structure of the website if you don't fully understand:
<html>
<head>
<head>
<body>
<form name="SplashBidNoticeAbstractUI" method="post" action="(some very long url)"
id="SplashBidNoticeAbstractUI">
<table id="Table6" cellspacing="1" cellpadding="1" width="90%" align="center" border="0">
<tbody>
<tr>
<td style="HEIGHT: 18px" align="center">
<span id="lblHeader" class="DisplayText6">Request for Quotation (RFQ)</span>
</td>
</tr>
<tr>
<td style="HEIGHT: 18px" align="center">
<!-- table inside a table start -->
<table class="Table" id="Table1" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="DisplayTextBackground" style="WIDTH: 20%">
<span id="lblReferenceNo" class="DisplayText4"
style="display:inline-block;width:136px;">Reference Number</span>
</td>
<td colspan="2"><span id="lblDisplayReferenceNo" class="DisplayText5">8564688</span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
(Sorry for the long code. It's just in the website I'm trying to take care of)
And there is also data that I want to extract from a table inside the table that contain Reference Number and 8564688.
And then here is the code from my Python file named web-s.py that I run to get the values:
from openpyxl import Workbook, load_workbook
from bs4 import BeautifulSoup
import requests
response = requests.get(
"https://notices.philgeps.gov.ph/GEPSNONPILOT/Tender/SplashBidNoticeAbstractUI.aspx")
soup = BeautifulSoup(response.text, "html.parser")
name = soup.find("td", {"id": "lblHeader"})
ref_num = soup.find("span", {"id": "lblReferenceNo"})
#soup.find('td', {'data-test': "specific-location"}).text.strip()
print(ref_num)
print(name)
#wb = load_workbook("crap.xlsx")
#ws = wb.active
And this is what I expect to see on the terminal or CMD:
C:\Users\aries\Desktop> python web-s.py
Request for Quotation (RFQ)
Reference Number
But the only thing that I get is:
C:\Users\aries\Desktop>python web-s.py
None
None
Am I missing something or there is a bug somewhere in the code?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
