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 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据