dongyi8416 2012-12-24 21:48
浏览 68
已采纳

使用curl检查仅限美国的网站状态

[Problem]

There is a website which works for US-citizens only (shows info "A" for US-citizens, info "B" for non-US citizens). I need to constantly monitor this webpage for changes ("A" info) - an email should be sent when something is changed! How do I do it? The problem is that I live in Europe!

[Already accomplished]

I have a linux server, daemon and curl PHP script which accomplishes the following task! It works great for all "non-US-only" websites.

[Question]

One way to solve the problem might be to rent a US server but that's not acceptable at all and it is going to cost a lot! I believe that another way to solve the problem might be - to use a US VPN on my server, but for some reasons I won't do that. Is there a way to run curl through proxy maybe? Any ideas?

Current code is the following:

function getrequest($url_site/*,$post_data*/) {
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL,$url_site);
    curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);  
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);   // Cookie management.
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
    $result = curl_exec($ch); // run the whole process 
    curl_close($ch);

    return $result;
}

and

 $sleep_time = 1;
 $login_wp_url = "http://www.mysite.com";
 set_time_limit(60*10);
 $result = getrequest($login_wp_url);

How do I grab contents from US-only website?

P.S. to get the idea of what I mean - try visiting the Hulu from Europe countries. P.P.S. that's not a Hulu, not a homework.

  • 写回答

1条回答 默认 最新

  • drfif48428 2012-12-24 21:55
    关注

    Many cloud service providers, e.g. Heroku and Amazon, offer their smallest instances for free. You could simply set up one of these for free, make sure that you are provisioned on an US-located server and run your script there.

    Another possibility would be to use a (free) proxy for these requests. Here is a list of free proxie servers: http://www.xroxy.com/proxy-country-US.htm.

    curl_setopt($ch, CURLOPT_PROXY, "http://160.76.xxx.xxx:8080");
    curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
    curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "xxx:xxx");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大