【发布时间】:2021-12-29 15:28:33
【问题描述】:
我在抓取该网站的表格时遇到问题,我应该得到标题,但得到的是
AttributeError: 'NoneType' object has no attribute 'tbody'
我对网络抓取有点陌生,所以如果你能帮助我,那就太好了
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)
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup python-requests