我一直在尝试删除有关某个项目的房地产新属性的信息数据。 尝试从网上获取床位数时,出现错误“ NoneType”对象没有属性“ get_text”。我不仅可以得到卧室的其他属性,而且可以得到
这是我的代码
titles = []
prices = []
super_area = []
bhk = []
move = []
for post in item:
title = post.find(id='srp_tuple_property_title').get_text().strip()
price = post.find(id='srp_tuple_price').get_text().strip()
area = post.find(id='srp_tuple_primary_area').get_text().strip()
moves = post.find(class_='badges__secondaryLargeSubtle').get_text().strip()
bed = post.find(id='srp_tuple_bedroom').get_text().strip()
bhk.append(bed)
move.append(moves)
super_area.append(area)
prices.append(price)
titles.append(title)
答案 0 :(得分:1)
尝试使用基础API。过滤后检查实际的API调用将为您提供正确的URL。
import requests
url = "https://www.99acres.com/api-aggregator/project/searchWidget?area_unit=1&platform=DESKTOP&moduleName=GRAILS_SRP&workflow=GRAILS_SRP&city=45&preference=S&res_com=R&page=1&page_size=10&isCrossSell=false"
data = requests.get(url=url).json()
print(data['newProjects'][1]['propTypeStr'])
# 2 BHK Apartment
过滤将更改URL的参数,例如:
https://www.99acres.com/api-aggregator/srp/search?bedroom_num=3&budget_min=136&locality_array=6046%2C6038&area_min=1900&area_unit=1&localityNameMap=%5Bobject%20Object%5D&platform=DESKTOP&moduleName=GRAILS_SRP&workflow=GRAILS_SRP&page_size=30&page=1&city=45&preference=S&res_com=R&seoUrlType=DEFAULT
这可以用urllib
来分解:
from urllib import parse
url = "https://www.99acres.com/api-aggregator/srp/search?bedroom_num=3&budget_min=136&locality_array=6046%2C6038&area_min=1900&area_unit=1&localityNameMap=%5Bobject%20Object%5D&platform=DESKTOP&moduleName=GRAILS_SRP&workflow=GRAILS_SRP&page_size=30&page=1&city=45&preference=S&res_com=R&seoUrlType=DEFAULT"
parse.parse_qs(parse.urlparse(url).query)
# {'bedroom_num': ['3'],
# 'budget_min': ['136'],
# 'locality_array': ['6046,6038'],
# 'area_min': ['1900'],
# 'area_unit': ['1'],
# 'localityNameMap': ['[object Object]'],
# 'platform': ['DESKTOP'],
# 'moduleName': ['GRAILS_SRP'],
# 'workflow': ['GRAILS_SRP'],
# 'page_size': ['30'],
# 'page': ['1'],
# 'city': ['45'],
# 'preference': ['S'],
# 'res_com': ['R'],
# 'seoUrlType': ['DEFAULT']}