我在抓取该网站的表格时遇到问题,我应该得到标题,但我却得到了
AttributeError: 'NoneType' object has no attribute 'tbody'
Run Code Online (Sandbox Code Playgroud)
我对网络抓取有点陌生,所以如果你能帮助我那就太好了
import requests
from bs4 import BeautifulSoup
URL = "https://www.collincad.org/propertysearch?situs_street=Willowgate&situs_street_suffix" \
"=&isd%5B%5D=any&city%5B%5D=any&prop_type%5B%5D=R&prop_type%5B%5D=P&prop_type%5B%5D=MH&active%5B%5D=1&year=2021&sort=G&page_number=1"
s = requests.Session()
page = s.get(URL)
soup = BeautifulSoup(page.content, "lxml")
table = soup.find("table", id="propertysearchresults")
table_data = table.tbody.find_all("tr")
headings = []
for td in table_data[0].find_all("td"):
headings.append(td.b.text.replace('\n', ' ').strip())
print(headings)
Run Code Online (Sandbox Code Playgroud) python beautifulsoup web-scraping python-3.x python-requests