如何从这个特定的URL抓取内容


PHP How to scrape content from this specific URL

有人能告诉我他们如何从像这个URL https://www.wayfair.com/The-Childrens-Factory-48-H-x-24-W-Mirror-CF332-132-GBS1086.html这样的页面获得产品的价格吗

我已经试了好几天了,还是没有运气。

感谢您的帮助

将next代码复制粘贴到PHP文件中,并在浏览器中运行:

<?php
// ▼ FIRST, GET THE WHOLE HTML FROM THE WEB PAGE.
$all = file_get_contents("https://www.wayfair.com/The-Childrens-Factory-48-H-x-24-W-Mirror-CF332-132-GBS1086.html");
$pos = strpos( $all,"dynamic-sku-price" ); // ◄■■ PRICE TAG.
$pos += 36; // SKIP SOME HTML CHARS.
while ( $all[ $pos ] != chr( 10 ) ) // ◄■■ GET PRICE CHARS UNTIL END OF LINE.
{ echo $all[ $pos ];
  $pos++;
}
?>

下载本页的html字符串并使用DOM xpath进行解析