我试图从www.dotabuff.com检索数据以获取蒸汽ID列表,但我只得到回报"我们无法找到您要找的东西!&# 34。
目标是访问网站,用他的汽车ID搜索玩家并提取他的胜率。
(这适用于非常小的列表,不会打扰dotabuff)。
这是我的代码(带有静态蒸汽ID的示例):
//create array of data to be posted
$post_data['utf8'] = '✓';
$post_data['q'] = '76561198055615656';
$post_data['commit'] = 'Search';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
curl_init('https://www.dotabuff.com//');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
echo $result;
//close the connection
curl_close($curl_connection);
答案 0 :(得分:0)
你正在使用带有curl的POST来进行搜索,但是看看Dotabuff网站的搜索表单正在使用GET,所以我怀疑该网站正在寻找GET vars而不是POST vars。我没有对此进行测试,但我建议对https://www.dotabuff.com/search?q=76561198055615656执行curl请求(不使用POSTFIELDS)并查看它给你的内容。
答案 1 :(得分:0)
没有网址的初始卷曲,或者汇集网址的GET版本并将其发布到网站。
例如,如果您想要有关用户&USH的信息!' (我简单地选择了一个)。您要合成的网址如下所示:
https://www.dotabuff.com/search?utf8=%E2%9C%93&q=USH%21&button=
我建议使用urlencode将播放器ID转换为GET URI安全字符串
例如:
$safe_player_id = urlencode($player_id)
$URI = sprintf("https://www.dotabuff.com/search?q=%s&button=",$safe_player_id);
或者,如果您知道他们的玩家ID代码(int),那么这将获得统计页面(这是有效的):
https://www.dotabuff.com/players/76561198055615656
然后你只需要解析你想要的页面。