我正在嘗試抓取此網站https://www.edgeprop.sg/condo-apartment/aquarius-by-the-park以獲取概覽表中的土地面積 (sqm)。結果應該給我 40,608
但是,我無法得到我想要的結果:( 這是我的代碼
#[Python] test webscrap on edgeprop
import gspread
import json
from oauth2client.service_account import ServiceAccountCredentials
from openpyxl.worksheet import worksheet
from requests.api import request
import requests
import time
from requests.models import Response
import scrapy
from bs4 import BeautifulSoup
from six import add_metaclass, class_types
query_string='https://www.edgeprop.sg/condo-apartment/aquarius-by-the-park'
resp = requests.get(query_string)
soup = BeautifulSoup(resp.content,'html.parser')
print("soup is: ", query_string)
try:
landsize = soup.find_all("h4",class_="detail-title__text")
print("Landsize is: ", landsize)
except IndexError:
pass
如您所見,我對此非常陌生,希望能就此尋求您的指導:)
uj5u.com熱心網友回復:
嘗試這個:
import json
import requests
from bs4 import BeautifulSoup
query_string='https://www.edgeprop.sg/condo-apartment/aquarius-by-the-park'
resp = requests.get(query_string)
soup = BeautifulSoup(resp.content,'html.parser')
# get data with all info
data = soup.find("script", id="__NEXT_DATA__").text
# convert string to python dict
json_data = json.loads(data)
# get land_size from dict
print(json_data["props"]["pageProps"]["projectInfo"]["data"]["land_size"])
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/369469.html
