我正在尝试使用PHP来获取项目的Steam社区市场价格.我拿一个网址(例如:http://steamcommunity.com/market/listings/730/StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29)然后我下载了内容file_get_contents().我试着用这个:
function getInnerHTML($string, $tagname, $closetagname) {
$pattern = "/<$tagname ?.*>(.*)<\/$closetagname>/";
preg_match($pattern, $string, $matches);
return $matches[1];
}
Run Code Online (Sandbox Code Playgroud)
运用
getInnerHTML($str, 'span class="market_listing_price market_listing_price_with_fee"', 'span');
Run Code Online (Sandbox Code Playgroud)
我可以使用file_get_contents的一个例子是:
<span class="market_table_value">
<span class="market_listing_price market_listing_price_with_fee">
$1.92 </span>
<span class="market_listing_price market_listing_price_without_fee">
$1.68 </span>
<br/>
</span>
Run Code Online (Sandbox Code Playgroud)
但它什么也没有回报.
有人有想法吗?