我尝试了 file_get_content
和 curl 来获取当我在浏览器中打开时显示的页面数据,但什么也没得到。
URL 在浏览器中打开,但是当我使用 curl 时,我重定向到主页,我使用什么方法来完成抓取页面以及我响应中的所有数据。
function curl($url) { $agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $data = curl_exec($ch); $info = curl_getinfo($ch); print_r($info); echo "curl error".curl_error($ch); curl_close($ch); echo $data; return $data; } $secState = '70'; $rankYear = 2013; $url = 'https://tennislink.usta.com/tournaments/rankings/rankinghome.aspx#Action=1&SectionDistrict='.$secState.'&Year='.$rankYear.'&Division=G8&ListType=0'; echo $url; $html=curl($url); echo $html;
最佳答案
您确定您的网址正确吗? &
和 SectionDistrict
你可以用下面的方法再试一次
$url = 'https://tennislink.usta.com/tournaments/rankings/rankinghome.aspx#Action=1&SectionDistrict='.$secState.'&Year='.$rankYear.'&Division=G8&ListType=0';
此 url 还应与 file_get_contents
一起使用
关于php - 使用 curl 从 asp.net 页面获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835919/