Как найти текст в теге td?
Получил такие данные через beatidulsoup
<td class="Value FormTd" id="p_body_fld_c3a5t2r34212155b1f173" z="custom.wgs_широта" zfieldshape="eSingleLine" zfieldtype="eDouble" ztags="координаты">42,831682</td>
как получить 42,831682? Вот мой отрывок кода:
browser = webdriver.Chrome()
browser.get(url)
open_search = browser.find_element(By.NAME, "p$body$ListSearch$listSearchBox")
open_search.send_keys(bsfull +'\n')
time.sleep(5)
soup = BeautifulSoup(browser.page_source, "html.parser")
candidate = soup.find_all(class_='fieldType-eString')
#print(candidate[9])
for linkCandidate in candidate[9]:
#print(linkCandidate)
print(f"+ Ссылка новой базовой станции: {linkCandidate['href']}\nИмя БС: {bsfull}")
#with open("output.log", "a") as outfile:
# outfile.write("+ New base station link "+linkCandidate['href']+"\nИмя БС:"+bsfull+"\n")
browser.get(linkCandidate['href'])
soup = BeautifulSoup(browser.page_source, "html.parser")
td = soup.find_all("td")
#print(type(str(td[6])))
if "УЦН" in str(td[6]):
ucn = "УЦН"
print(ucn)
dataList2.append(ucn)
else:
ucn = "-"
print(ucn)
dataList2.append(ucn)
print("Получены данные УЦН базовых станций, для которых нужно заполнить данные:")
print(dataList2)
with open("output.log", "a") as outfile:
outfile.write("+ The UCN data of the base stations has been received, for which the data needs to be filled in\n")
print(td[39])
#latitude = soup.find(td[39])
latitude = td[39].find(class_="Value FormTd").text
print(latitude)
выходит слеующая ошибка:
Получены данные УЦН базовых станций, для которых нужно заполнить данные:
['-']
<td class="Value FormTd" id="p_body_fld_c3a5t2r34212155b1f173" z="custom.wgs_широта" zfieldshape="eSingleLine" zfieldtype="eDouble" ztags="координаты">42,831682</td>
Traceback (most recent call last):
File "C:\Users\david.gabunia\tpojects\cesV3\py.py", line 448, in <module>
latitude = td[39].find(class_="Value FormTd").text
AttributeError: 'NoneType' object has no attribute 'text'
``