|
楼主 |
发表于 2017-12-4 11:14:51
|
显示全部楼层
本帖最后由 2949497060 于 2017-12-4 11:33 编辑
我把我的代码直接贴出来,飞哥帮我运行一下试试吧,除了cookie和post里的token参数可能失效外,其它应该都可以直接运行,cookie或者token要是失效了我就重新发:
string url = "https://subway.simba.taobao.com/bidword/add.htm";
string userAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1";
string referer = "https://subway.simba.taobao.com/";
string cookies = "UM_distinctid=15d72424f347e-0e8d76ef4eebbe-333f5902-13c680-15d72424f35c4e; thw=cn; miid=1802922913836622752; ali_apache_id=11.128.44.69.1503382547917.223399.7; cna=jX65EV/UIGECAavZYKGdAE5B; ali_ab=221.237.149.70.1497153809618.3; hng=CN%7Czh-CN%7CCNY%7C156; _tb_token_=fef6b737eb65e; cookie2=2d6d69f521f335fdbcbdfc316b765a65; mt=np=&ci=111_1; t=72a90b698f96021fcda47cf74c2a9d21; _cc_=URm48syIZQ%3D%3D; tg=0; _m_h5_tk=194decb65c7af50e5e60116ce0754df7_1512054169444; _m_h5_tk_enc=3b6508333200bf52082631e51d52c4da; CNZZDATA1000005116=2078402807-1512271320-https%253A%252F%252Fsubway.simba.taobao.com%252F%7C1512276611; CNZZDATA1000005136=2105699461-1512271730-https%253A%252F%252Fsubway.simba.taobao.com%252F%7C1512304957; x=407457629; uc3=sg2=UtIHatBaYdTuDE5RcR%2BZzmNKZxChZ48GwUqpB8LsiNM%3D&nk2=&id2=&lg2=; uc1=cookie14=UoTdeYfPRE5PNg%3D%3D&lng=zh_CN; uss=VFQh%2FMmTR57e4jA1l8ATVVthd9NxSkSdbBwWDaHcGtHWXwik6XYDvF2lXA%3D%3D; tracknick=; sn=lansingbike%3Afan; unb=789304910; skt=afe811880143cb52; l=AqenicJwCHgD3wQzhpFpwvWvt9BxLHsO; v=0; JSESSIONID=857CB5B77349789FB21D7F22D5BC4B51; CNZZDATA1000005137=870525305-1512270786-https%253A%252F%252Fsubway.simba.taobao.com%252F%7C1512350609; CNZZDATA1000005141=1246162653-1512268195-https%253A%252F%252Fsubway.simba.taobao.com%252F%7C1512352532; apushda7f530fa6bd3aed56e02fefca06cdd9=%7B%22ts%22%3A1512355911383%2C%22parentId%22%3A1512315593382%7D; isg=Avz8KKVfiqtqwL1kB-kKKciwzZpuXaB7SZhbNtZ9AufKoZwr_gVwr3If9f8i";
string token = "f93c91de";
string postData1 = "logsBidwordStr=&adGroupId=813719140&keywords=[{\"word\":\"dd花\",\"matchScope\":4,\"isDefaultPrice\":1,\"maxPrice\":\"0\"}]&analyseTraceId=&_op_context_action_id=&_op_context_data=[{\"adgroup_id\":\"813719140\",\"original\":\"dd花\",\"pack\":{\"source\":\"ZDY\",\"platform\":\"\",\"tags\":null},\"algo_v\":1,\"price_opt\":{\"opt\":\"mr\"}}]&sla=json&isAjaxRequest=true&token=" + token + "&_referer=/campaigns/standards/adgroups/items/detail?tab=bidword&campaignId=&adGroupId=";
string postData2 = "logsBidwordStr=&adGroupId=813719140&keywords=[{\"word\":\"dd%E8%8A%B1\",\"matchScope\":4,\"isDefaultPrice\":1,\"maxPrice\":\"0\"}]&analyseTraceId=&_op_context_action_id=&_op_context_data=[{\"adgroup_id\":\"813719140\",\"original\":\"dd%E8%8A%B1\",\"pack\":{\"source\":\"ZDY\",\"platform\":\"\",\"tags\":null},\"algo_v\":1,\"price_opt\":{\"opt\":\"mr\"}}]&sla=json&isAjaxRequest=true&token=" + token + "&_referer=/campaigns/standards/adgroups/items/detail?tab=bidword&campaignId=&adGroupId=";
string postData3 = "logsBidwordStr=&adGroupId=813719140&keywords=%5b%7b%22word%22%3a%22dd%e8%8a%b1%22%2c%22matchScope%22%3a4%2c%22isDefaultPrice%22%3a1%2c%22maxPrice%22%3a%220%22%7d%5d&analyseTraceId=&_op_context_action_id=&_op_context_data=%5b%7b%22adgroup_id%22%3a%22813719140%22%2c%22original%22%3a%22dd%e8%8a%b1%22%2c%22pack%22%3a%7b%22source%22%3a%22ZDY%22%2c%22platform%22%3a%22%22%2c%22tags%22%3anull%7d%2c%22algo_v%22%3a1%2c%22price_opt%22%3a%7b%22opt%22%3a%22mr%22%7d%7d%5d&sla=json&isAjaxRequest=true&token=" + token + "&_referer=%2fcampaigns%2fstandards%2fadgroups%2fitems%2fdetail%3ftab%3dbidword%26campaignId%3d%26adGroupId%3d";
string postCode = "utf-8";
postCode = txtCode.Text;
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse httpResp = null;
string postResult = "";
try
{
httpReq.Method = "POST";
httpReq.UserAgent = userAgent;
httpReq.Referer = referer;
httpReq.Timeout = 25000;
httpReq.KeepAlive = true;
httpReq.ContentType = "application/x-www-form-urlencoded";
httpReq.Headers[HttpRequestHeader.Cookie] = cookies;
byte[] bytesData1 = Encoding.GetEncoding(postCode).GetBytes(postData3);
httpReq.ContentLength = bytesData1.Length;
Stream postStream1 = httpReq.GetRequestStream();
postStream1.Write(bytesData1, 0, bytesData1.Length);
httpResp = (HttpWebResponse)httpReq.GetResponse();
postResult = new StreamReader(httpResp.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
MessageBox.Show(postResult);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
if (httpResp != null)
{
httpResp.Close();
}
httpReq.Abort();
}
System.Text.RegularExpressions.Match mchWord = System.Text.RegularExpressions.Regex.Match(postResult, "您输入的关键词((?<repeatword>.*?))与已有词重复");
if (mchWord.Value != "")
{
//如果已有重复,此处就能看见结果是否乱码
txtResult.Text = "已有重复,提交词为“dd花”,结果词为:“" + mchWord.Groups["repeatword"].Value + "”";
return;
}
if (postResult.Contains("\"code\":\"200\",\"msg\":null,"))
{
//postData为提交的结果,200说明提交成功,然后再到另一个页面查看提交的文字结果是否乱码
string url2 = "https://subway.simba.taobao.com/bidword/list.htm";
string pd2 = "campaignId=3010863&adGroupId=813719140&queryWord=&queryType=0&sla=json&isAjaxRequest=true&token=" + token + "&_referer=%2Fcampaigns%2Fstandards%2Fadgroups%2Fitems%2Fdetail%3Ftab%3Dbidword%26campaignId%3D%26adGroupId%3D";
httpReq = (HttpWebRequest)WebRequest.Create(url2);
try
{
httpReq.Method = "POST";
httpReq.UserAgent = userAgent;
httpReq.Referer = referer;
httpReq.Timeout = 25000;
httpReq.KeepAlive = true;
httpReq.ContentType = "application/x-www-form-urlencoded";
httpReq.Headers[HttpRequestHeader.Cookie] = cookies;
byte[] bytesData1 = Encoding.GetEncoding("utf-8").GetBytes(pd2);
httpReq.ContentLength = bytesData1.Length;
Stream postStream1 = httpReq.GetRequestStream();
postStream1.Write(bytesData1, 0, bytesData1.Length);
httpResp = (HttpWebResponse)httpReq.GetResponse();
string htmlResult = new StreamReader(httpResp.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
txtResult.Text = htmlResult;
System.Text.RegularExpressions.MatchCollection mchsWord = System.Text.RegularExpressions.Regex.Matches(htmlResult, "\"keywordId\":\"(?<keywordid>\\d+)\",\"word\":\"(?<word>[^\"]*?)\"");
if (mchsWord.Count > 0)
{
string words = "当前所有词:";
foreach (System.Text.RegularExpressions.Match mch in mchsWord)
{
words += "\r\n" + mch.Groups["word"].Value;
}
txtResult.Text = words + "\r\n\r\n-----------\r\n" + txtResult.Text;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
if (httpResp != null)
{
httpResp.Close();
}
httpReq.Abort();
}
} |
|