我想提取本網站的所有鏈接:https ://pflegefinder.bkk-dachverband.de/pflegeheime/searchresult.php?required=1&statistics=1&searchdata[maxDistance]=0&searchdata[careType]=inpatientCare#/tab/general
我要的資訊存放在tbody: page code
每次我嘗試提取資料時都沒有結果。
from bs4 import BeautifulSoup
import requests
from requests_html import HTMLSession
url = "https://pflegefinder.bkk-dachverband.de/pflegeheime/searchresult.php?required=1&statistics=1&searchdata[maxDistance]=0&searchdata[careType]=inpatientCare#complex-searchresult"
session = HTMLSession()
r = session.get(url)
r.html.render()
soup = BeautifulSoup(r.html.html,'html.parser')
print(r.html.search("Details"))
謝謝您的幫助!
uj5u.com熱心網友回復:
該站點使用后端 api 來傳遞資訊,如果您查看瀏覽器的開發人員工具 - 網路 - 獲取/XHR 并重繪 頁面,您將在請求中看到通過 json 加載的資料,該請求具有與您發布的類似的 url .
您可以像這樣抓取該資料,它回傳的 json 很容易決議:
import requests
headers = {
'Referer':'https://pflegefinder.bkk-dachverband.de/pflegeheime/searchresult.php?required=1&statistics=1&searchdata[maxDistance]=0&searchdata[careType]=inpatientCare',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
}
for page in range(2):
url = f'https://pflegefinder.bkk-dachverband.de/api/nursing-homes?required=1&statistics=1&maxDistance=0&careType=inpatientCare&limit=20&offset={page*20}'
resp = requests.get(url,headers=headers).json()
print(resp)
api 檢查您是否有“Referer”標頭,否則您會收到 400 回應。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/417664.html
標籤:
上一篇:beautifulsoup通過span標簽之間的空格獲取文本
下一篇:如何通過元將資料點作為專案傳遞?
