想要爬取下方內容裡的numSoldTickets但語法錯誤,想請問要如和修正才能爬取,謝謝!
你可以試試看以下程式碼:
import requests
import json
from bs4 import BeautifulSoup
url = "https://api.hahow.in/api/group/photography/courses?page=1"
res = requests.get(url, headers={
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"})
soup = BeautifulSoup(res.text, "html.parser")
resJson = json.loads(res.text)
for item in resJson["data"]:
print(item["successCriteria"]["numSoldTickets"])