【发布时间】:2020-06-19 03:38:16
【问题描述】:
由于出现以下错误,我无法使用 bs4 从该网页中提取数据
"AttributeError: 'NoneType' object has no attribute 'text'"
有人可以修改我的代码吗?
这是我的代码
from bs4 import BeautifulSoup
import requests
url = 'https://e-masjid.jais.gov.my/index.php/profail?page=1'
html_content = requests.get(url).text
soup = BeautifulSoup(html_content, 'lxml')
masjid_table = soup.find("table", attrs={"class": "Masjid"})
masjid_table_data = masjid_table.tbody.find_all("tr")
headings = []
for td in masjid_table_data[0].find_all("td"):
headings.append(td.b.text.replace('\n', ' ').strip())
print(headings)masjid_table = soup.find("table", attrs={"class": "Masjid"})
masjid_table_data = masjid_table.tbody.find_all("tr")
headings = []
for td in masjid_table_data[0].find_all("td"):
headings.append(td.b.text.replace('\n', ' ').strip())
print(headings)
【问题讨论】:
-
你想提取什么,你能添加一些示例输出吗?
-
尝试打印(汤),结果如何。
-
你可以在这里查看输出pastebin.com/nrhL7RPB
标签: python beautifulsoup