【发布时间】:2011-07-21 10:32:36
【问题描述】:
我正在尝试使用 xpath 来抓取一个站点,但初始站点是一个小部件而不是原始 html,所以我需要某种方式来执行小部件代码来获取 html。
我要抓取的网址是:https://www.dealcurrent.com/customwidget.php?publisherID=36&widget=largewidget
如果我回显 curl_exec 返回的 $html,它会给我正确呈现的 html,但如果我直接打印出 $html,它会给我类似的东西:
<br />[ ]<br>[ try {if(window.top.location==document.URL) document.write('<meta http-equiv=refresh content="0;url=\'http://www.sweetfind.com/\'"/>'); } catch(e) {}Sweet Findif(34>=10000) window.location.href="https://www.dealcurrent.com/customwidget.php?widget=largewidget_soldout&publisherID=36"; #nav a:link { color:#666666; font-family:Arial, Helvetica, sans-serif; font-size:12px; text-decoration:none; } #nav a:visited { font-family:Arial, Helvetica, sans-serif; color:#666666; text-decoration:none; font-size:12px; text-decoration:none; } #nav a:hover { font-family:Arial, Helvetica,
等等……
有什么方法可以“执行”上面的代码来获取 html 输出,以便我可以将它与 xpath 一起使用?
【问题讨论】:
-
你试过关注位置吗
-
javascript 似乎正在插入一个 html meta -edirect(因此跟随位置可能不起作用)。你能指定你试图抓取的哪个页面吗?如果它是您被重定向到的任何内容,只需使用 strpos 来分解元重定向。
标签: php curl web-scraping