EDITED
首先,抱歉额外的php标签。我认为可能涉及到php的解决方案。
其次,让我道歉,我并不熟悉任何网络内容。我碰巧知道一点点bash所以当我需要模仿一个常设连接时,我才会想到卷曲。我知道这可能不是最好的,甚至是正确答案。
然后回答“10 s”时间问题。我不确定该网站如何跟踪“页面时间”。我知道一些网站使用.js + php来做,但我不知道这里的确切机制。
感谢您的一些评论,现在我明白使用curl发送http请求可能与模仿持久浏览行为不同。我将研究Selenium,但是非常感谢bash友好的命令行解决方案。
最后,使用--keepalive-time,我得到与没有它的命令完全相同的结果。详细输出。谢谢大家。
# curl --keepalive-time 20 "http://s.weibo.com/weibo/%25E8%2596%259B%25E4%25B9%258B%25E8%25B0%25A6%2B%25E9%2581%2597%25E6%2586%25BE&Refer=STopic_top" -v
* Trying 180.149.135.239...
* TCP_NODELAY set
* Connected to s.weibo.com (180.149.135.239) port 80 (#0)
> GET /weibo/%25E8%2596%259B%25E4%25B9%258B%25E8%25B0%25A6%2B%25E9%2581%2597%25E6%2586%25BE&Refer=STopic_top HTTP/1.1
> Host: s.weibo.com
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 08 Sep 2017 23:43:55 GMT
< Server: Apache
< Set-Cookie: U_TRS1=0000004f.76de757d.59b32b3b.b76cc844; path=/; expires=Mon, 06-Sep-27 23:43:55 GMT; domain=.sina.com.cn
< Set-Cookie: U_TRS2=0000004f.76f3757d.59b32b3b.a51684a9; path=/; domain=.sina.com.cn
< Cache-Control: no-cache, must-revalidate
< Expires: Sat, 26 Jul 1997 05:00:00 GMT
< X-Frame-Options: DENY
< Pragma: no-cache
< DPOOL_HEADER: dagda83
< Vary: Accept-Encoding
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
< SINA-LB:aGEuMjA3LmcxLnlmLmxiLnNpbmFub2RlLmNvbQ==
< Set-Cookie: SWB=usrmdinst_12; path=/
< SINA-TS:YTJlODk4Y2UgMCAwIDAgMTEgMzgK
<
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-Frame-Options" content="DENY " />
<meta content="IE=8" http-equiv="X-UA-Compatible" />
<title>微博搜索 - 薛之谦 遗憾 - 微博</title>
<noscript>
<meta http-equiv="refresh" content="0;url=/home?nojs=1">
</noscript>
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/module/common.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/pages/weibo.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" /><link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/module/search_directarea.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/module/general.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/module/hot_ranktit.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<script type="text/javascript">
var $CONFIG = {};
$CONFIG['islogin'] = '0';
$CONFIG['uid'] = '0';
$CONFIG['entry'] = 'weisousuo';
$CONFIG['setCover'] = 1; //ie6hack
$CONFIG['version'] = '201709071330';
$CONFIG['bigpipe'] = 'true';
$CONFIG['timeDiff'] = (new Date() - 1504914235000);
$CONFIG['product'] = 'search';
$CONFIG['pageid'] = 'weibo';
$CONFIG['skin'] = '';
$CONFIG['lang'] = 'zh-cn';
$CONFIG['jsPath'] = 'https://js.t.sinajs.cn/t4/';
$CONFIG['cssPath'] = 'https://img.t.sinajs.cn/t4/';
$CONFIG['imgPath'] = 'https://img.t.sinajs.cn/t4/';
$CONFIG['servertime'] = 1504914235;
$CONFIG['ad_url_jump'] = '';
$CONFIG['bpType'] = 'main';
$CONFIG['$webim'] = 0;
$CONFIG['mJsPath'] = ['https://js{n}.t.sinajs.cn/t4/', 1, 2];
$CONFIG['mCssPath'] = ['https://img{n}.t.sinajs.cn/t4/', 1, 2];
$CONFIG['s_domain'] = 'http://s.weibo.com';
$CONFIG['s_search'] = '%25E8%2596%259B%25E4%25B9%258B%25E8%25B0%25A6%2520%25E9%2581%2597%25E6%2586%25BE';
</script><!--[if lte IE 8]>
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/pages/ie_bug.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<![endif]-->
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/base/usually.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/module/WB_h5video.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
</head>
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/module/rela_person.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<body class="S_weibo ">
<div class="S_wrap ">
<div id="weibo_top_public"></div>
<link href="https://img.t.sinajs.cn/t4/appstyle/searchV45/css_v6/module/direct_weiguantuan.css?version=201709071330" type="text/css" rel="stylesheet" charset="utf-8" />
<!-- new usercard-->
<script src="https://js.t.sinajs.cn/t5/pack/js/bootstrap.js"></script>
<script>
WBWidget({
}).load();
</script>
<script src="https://js.t.sinajs.cn/t5/pack/static/musicplayer/musicplayer_stk_v6.1.5.js"></script>
<!-- // <script src="http://js.t.sinajs.cn/trunk_musicplayer/js/exports/musicplayer_stk.js"></script> -->
<script>
//设置用户uid 用于同步赞状态
WEIBO_MUSIC_PLAYER.load({page_id:''});
//监听赞事件
//监听分享事件
WEIBO_MUSIC_PLAYER.on('share', function (evt, song) {
alert(song.copy);
song //歌曲的所有信息
});
</script>
<div class="S_main">
<div class="S_main_bg">
<div class="search_head clearfix" id="pl_common_searchTop"></div>
<div class="S_plwrap" id="pl_common_unLogin">
<div class="S_plc" id="plc_main">
<div class="S_content clearfix">
<div class="S_content_l">
<div id="pl_common_sassfilter"></div>
</div>
<div class="S_content_r"></div>
</div>
</div>
</div>
</div>
</div>
<div class="search_footer W_textb">
<div class="global_footer">
<div class="other_link clearfix">
<div class="help_link">
<p>
<a class="ico_service" href="http://ir.weibo.com/?bottomnav=1&wvr=5" target="_blank">关于微博</a>
<a href="http://help.weibo.com/?refer=didao&bottomnav=1&wvr=5" target="_blank">微博帮助</a>
<a href="http://help.weibo.com/newtopic/suggest?bottomnav=1&wvr=5" target="_blank">意见反馈</a>
<a href="http://open.weibo.com/?bottomnav=1&wvr=5" target="_blank">开放平台</a>
<a href="http://hr.weibo.com/?bottomnav=1&wvr=5" target="_blank">微博招聘</a>
<a href="http://news.sina.com.cn/guide/?bottomnav=1&wvr=5" target="_blank">新浪网导航</a>
<a href="http://service.account.weibo.com/?bottomnav=1&wvr=5" target="_blank">社区管理中心</a>
<a href="http://service.account.weibo.com/roles/gongyue?bottomnav=1&wvr=5" target="_blank">微博社区公约</a>
</p>
<p class="company"><span class="copy S_txt2">Copyright © 2009-2017 WEIBO 北京微梦创科网络技术有限公司</span>
<span>
<a href="http://weibo.com/aj/static/jww.html" target="_blank" class="S_txt2">京网文[2011]0398-130号</a><a href="http://www.miibeian.gov.cn" target="_blank" class="S_txt2">京ICP备12002058号</a>
</span></p>
</div>
</div>
</div>
</div>
<!-- 返回,分享 -->
<div class="S_gotop" id="base_scrollToTop">
<a suda-data="key=tblog_search_weibo&value=weibo_up" node-type="scrollToTop" class="W_gotop S_ficon_bg" href="javascript:void(0);" style="display:;"><em class="W_ficon ficon_backtop S_bg2_c">Ú</em></a> </div>
<!-- <div class="right_btn" id="base_scrollToTop">
<ul class="btn_list">
<li node-type="scrollToTop" style="display:;"><a href="javascript:void(0);" class="bottom_btn" title=返回顶部 suda-data="key=tblog_search_v4.1&value=weibo_feed_back"><span><em class="btn_icon"><i class="search_icon icon_top"></i></em><em class="btn_txt">顶部</em></span></a></li>
<li><a href="http://weibo.com/wbsearch?Refer=STopic_feedback" title=提交使用反馈 target="_blank" class="bottom_btn" suda-data="key=tblog_search_v4.1&value=weibo_feed_feedback"><span><em class="btn_icon"><i class="search_icon icon_feedback"></i></em><em class="btn_txt">反馈</em></span></a></li>
</ul>
</div> -->
<!-- /返回,分享 -->
<div style="display:none;" id="pl_common_base"></div>
</div>
</body>
<script src="http://js.t.sinajs.cn/t6/home/js/pl/top/topInit.js"></script>
<script type="text/javascript">
(function() {
WBtopGlobal && WBtopGlobal.init({
'islogin': 0,
"backurl":"http://s.weibo.com"
});
})();
</script>
<script src="https://js.t.sinajs.cn/t4/apps/search_v6/js/base.js?version=201709071330" type="text/javascript" ></script>
<!-- 视频播放 -->
<script type="text/javascript" charset="UTF-8" src="https://js.t.sinajs.cn/video/sinaplayer/js/page/player.js"></script>
<script type="text/javascript" charset="UTF-8" src="https://js.t.sinajs.cn/t6/page/js/pl/third/search/index.js?version=2017090907"></script>
<!-- SUDA_CODE_START -->
<noscript><img width="0" height="0" src="http://beacon.sina.com.cn/a.gif?noScript" border="0" alt="" /></noscript>
<!-- SUDA_CODE_END -->
<script>STK && STK.pageletM && STK.pageletM.view({"pid":"pl_common_sassfilter","js":["apps\/search_v6\/js\/pl\/common\/sassfilter.js?version=201709071330"],"css":[],"html":"<div class=\"WB_cardwrap S_bg2\">\n<div class=\"code_box clearfix\">\n <div class=\"code_ver\">\n <p class=\"code_tit\">\u4f60\u7684\u884c\u4e3a\u6709\u4e9b\u5f02\u5e38\uff0c\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801\uff1a<\/p>\n <div class=\"code_wrap\">\n <div class=\"form_table veri_code clearfix\">\n <span class=\"code_input\"><input type=\"text\" class=\"W_inputStp\" node-type=\"yzm_input\"><\/span> \n <span class=\"code_img\"><img src=\"\/ajax\/pincode\/pin?type=sass&ts=1504914235\" node-type=\"yzm_img\"><\/span>\n <a class=\"code_change\" node-type=\"yzm_change\" href=\"javascript:void(0);\">\u770b\u4e0d\u6e05\uff0c\u6362\u4e00\u5f20<\/a> \n <\/div>\n <div class=\"veri_state\"><div class=\"M_notice_del\" style=\"display:none;\" node-type=\"yzm_error\"><span class=\"icon_del\"><\/span><span class=\"txt\">\u9a8c\u8bc1\u7801\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165<\/span><\/div><\/div>\n <div class=\"code_btn\"><a class=\"S_btn_b\" href=\"javascript:void(0);\" node-type=\"yzm_submit\"><span>\u6211\u771f\u6ef4\u4e0d\u662f\u673a\u5668\u4eba<\/span><\/a><\/div>\n <\/div>\n <\/div>\n<\/div>\n<\/div>"})</script>
<script>STK && STK.pageletM && STK.pageletM.view({"pid":"pl_common_base","js":["apps\/search_v6\/js\/pl\/common\/changeLanguage.js?version=201709071330","apps\/search_v6\/js\/pl\/common\/base.js?version=201709071330"],"css":[],"html":""})</script>
* Curl_http_done: called premature == 0
* Closing connection 0
</html>
原帖:
我想模仿网站访问并模仿用户在网页上停留超过10秒。
现在我已经curl做了访问工作,但是在curl命令完成后,连接似乎立即关闭。花费的时间可以忽略不计。
我已经读过一些关于--keepalive的帖子,但它似乎没有帮助。
结果:
%收到的总百分比%Xferd平均速度时间时间当前时间 Dload上载总左转速度
100 8931 0 8931 0 0 18287 0 - : - : - - : - : - - : - : - - 18301
代码
for i in `seq 1 $count`; do
curl "${targeturl}" > /dev/null;
sleep 20;
done
我真的很感激有关如何做的任何提示。