免費公開課 · 聯絡 psyche@mail.grokbot.com
開始學習吧!勾選完成的課節。
0% 完成(0/5 課節)
提示:點擊課節即可標記/取消(存於本機)。完成後可滾動到對應分段。
與「瀏覽器自動化」(如 Playwright/Browser Use)不同:爬蟲多半直接打 HTTP;遇到重 JS 渲染才考慮無頭瀏覽器。
/robots.txt;尊重 Crawl-delay/Disallow。先安裝:pip install requests beautifulsoup4。請只對允許的目標練習。
import requests
from bs4 import BeautifulSoup
url = "https://example.com/" # 換成你有權爬的網址
headers = {"User-Agent": "CyberAI-Academy-Learner/1.0 (+mailto:you@example.com)"}
r = requests.get(url, headers=headers, timeout=20)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
print(soup.title.get_text(strip=True) if soup.title else "(no title)")
for a in soup.select("a[href]")[:10]:
print(a.get("href"), a.get_text(strip=True)[:60])
登入會員後可將整門課標記完成並同步至儀表板。