Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

วิธีดึงลิงก์เว็บไซต์ด้วย Invoke-WebRequest ใน PowerShell


คำสั่งพื้นฐาน

$req = Invoke-WebRequest -uri "https://example.com"
$req.Links

ดึงเฉพาะ URL (href)

$req.Links | Select-Object -ExpandProperty href

ตัวอย่างผลลัพธ์

https://example.com/page1
https://example.com/page2
https://example.com/category/powershell/
...

คำอธิบาย

  • Invoke-WebRequest ดึงเนื้อหาเว็บเพจ
  • Property .Links มีอ็อบเจกต์ลิงก์ พร้อม InnerHTML, InnerText, href, tagName
  • ใช้ Select-Object -ExpandProperty href เพื่อดึงเฉพาะ URL