ADURL简化程序
using System;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Web;
using System.Linq;
using System.IO;
using System.Collections.Generic;
namespace AdUrlConvert
{
class Program
{
public static string Finalurl;
public static string getProxyIP = System.Configuration.ConfigurationManager.AppSettings["proxyIP"];
public static int getproxyPORT = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["proxyPORT"]);
public static string getinputCsvPath = System.Configuration.ConfigurationManager.AppSettings["inputCsvPath"];
public static string getoutputCsvPath = System.Configuration.ConfigurationManager.AppSettings["outputCsvPath"];
static void Main(string[] args)
{
readUrlCsv();
}
public static string GetFinalAdUrl(string finlurl, string url)
{
try
{ Finalurl = finlurl;
string result = string.Empty;
HttpWebRequest request = WebRequest.Create(finlurl) as HttpWebRequest; //第一步:用工厂机制(factory mechanism)通过Create()方法来创建一个HttpWebRequest对象。
request.AllowAutoRedirect = false; // 获取或设置一个值,该值指示请求是否应跟随重定向响应。
WebProxy proxy = new WebProxy(getProxyIP, getproxyPORT);
request.Proxy = proxy;
HttpWebResponse response = request.GetResponse() as HttpWebResponse; //第二步:调用 HttpWebRequest.GetResponse()方法返回的是一个HttpWebResponse对象 while (response.Headers["Location"] != null)
{
try
{
Finalurl = response.Headers["Location"];
response.Close();
request = WebRequest.Create(Finalurl) as HttpWebRequest;
request.AllowAutoRedirect = false;
request.Referer = Finalurl;
response = request.GetResponse() as HttpWebResponse;
}
catch (Exception x)
{
Finalurl = "null";
LogHelper.WriteLog(typeof(Program), string.Format("今行ってURL:{0} 詳しい内容は {1}", url, x.Message));
break;
} }
LogHelper.WriteLog(typeof(Program), string.Format("今行ってURL:{0} 詳しい内容は {1}", url, "Finalurl:" + Finalurl)); response.Close();
}
catch (Exception ex)
{ LogHelper.WriteLog(typeof(Program), string.Format("今行ってURL:{0} 詳しい内容は {1}", url, ex.Message));
}
return Finalurl; #region 源码的获取
//Stream sr = response.GetResponseStream(); //从Internet资源返回数据流
//if (sr != null)
//{
// StreamReader reader = new StreamReader(sr, Encoding.UTF8); //读取数据流
// result = reader.ReadToEnd();
// reader.Close();
// sr.Close();
// request.Abort();
// response.Close();
//}
//url = response.Headers["Location"];
//response.Close(); //request = WebRequest.Create(url) as HttpWebRequest;
//request.AllowAutoRedirect = false;
//request.Referer = url;
//response = request.GetResponse() as HttpWebResponse;
//url = response.Headers["Location"];
//response.Close(); //request = WebRequest.Create(url) as HttpWebRequest;
//request.AllowAutoRedirect = false;
//request.Referer = url;
//response = request.GetResponse() as HttpWebResponse;
//url = response.Headers["Location"];
//response.Close();
//Console.WriteLine(url);
#endregion 源码的获取 } public static void readUrlCsv()
{
string path = getinputCsvPath;
UrlList ul = new UrlList();
ul.Finalurl = new List<string>();
ul.Finalurl.Add("最終URL");
ul.ADurlList = File.ReadAllLines(path, Encoding.UTF8).ToList();
int index = 1;
// 循环访问一遍 ul.ADurlList.Skip(1).ToList().ForEach(x =>
{
ul.Finalurl.Add(GetFinalAdUrl(ul.ADurlList[index],ul.ADurlList[index]));
index++;
});
// 对出错的重新访问
index = 1; ul.ADurlList.ForEach(x =>
{
if (ul.Finalurl[index] == null)
{
ul.Finalurl[index] = GetFinalAdUrl(ul.ADurlList[index], ul.ADurlList[index]);
index++;
}
});
index = 0;
// 生成最终的csv for (int i = 0; i < ul.ADurlList.Count; i++)
{
ul.ADurlList[i] += "," + ul.Finalurl[i];
}
File.WriteAllLines(getoutputCsvPath, ul.ADurlList);
}
}
}
ADURL简化程序的更多相关文章
- 利用freopen()函数和fc命令简化程序调试
大家在参加ACM比赛或者参加c/c++实验技能竞赛的时候,如果遇到大量的输入和大量的输出时,调试起来很不方便.一来如果结果不正确的话,需要重复输入大量数据:二来如果大量输出的话,得仔细检查输出结果与正 ...
- C与C++中的常用提高程序效率的方法
1.用a++和++a及a+=1代替a=a+1,用a--和--a及a-=1代替a=a-1 通常使用若把一个函数定义为内联函数,则在程序编译阶段,编译器就会把每次调用该函数的地方都直接替换为该函数体中的代 ...
- C/C++程序员应聘试题剖析(转载)
转载自:http://www.cnitblog.com/zouzheng/articles/21856.html 1.引言 本文的写作目的并不在于提供C/C++程序员求职面试指导,而旨在从技术上分析面 ...
- 程序猿,千万别说你不了解Docker!
放在两年前,你不认识Docker情有可原.但如果现在你还这么说,不好意思,我只能说你OUT了.你最好马上get起来,因为有可能你们公司很快就会引入Docker. 今天就和大家讨论讨论这个备受好评的应用 ...
- linux c程序中获取shell脚本输出的实现方法
linux c程序中获取shell脚本输出的实现方法 1. 前言Unix界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些夸张,但不可否认的是,借助脚本确实能够极大的简化一些编程工作. ...
- matlab练习程序(矩形变换为单连通形状)
变换使用的模板必须是单连通的,而且模板中心必须在模板内,如果在模板中打个结或是月牙形,这里的程序就处理不了了. 虽然非单连通模板也有办法处理,不过不是这里要讨论的. 这里用到的方法和矩形变换为圆那片文 ...
- Java程序员面试宝典1 ---Java基础部分(该博文为原创,转载请注明出处)
(该博文为原创,转载请注明出处 http://www.cnblogs.com/luyijoy/ by白手伊凡) 1. 基本概念 1) Java为解释性语言,运行过程:程序源 ...
- [转]100个经典C语言程序(益智类问题)
目录: 1.绘制余弦曲线 2.绘制余弦曲线和直线 3.绘制圆 4.歌星大奖赛 5.求最大数 6.高次方数的尾数 8.借书方案知多少 9.杨辉三角形 10.数制转换 11.打鱼还是晒网 12.抓交通肇事 ...
- 【转】C/C++程序员应聘常见面试题深入剖析
1.引言 本文的写作目的并不在于提供C/C++程序员求职面试指导,而旨在从技术上分析面试题的内涵.文中的大多数面试题来自各大论坛,部分试题解答也参考了网友的意见. 许多面试题看似简单,却需要深厚的基 ...
随机推荐
- Atom插件推荐
1.File Icons 为各种不同的文件显示icon 2.git plus 添加git的功能 3.atom-beauty 代码格式化工具 4.eclipse keybindings 在atom上使用 ...
- jquery mobile button样式设置
<a href="#" class="ui-btn">提交</a> ui-btn表示按钮样式 ui-btn-a,ui-btn-b:the ...
- delphi 文件删除,复制
这是个相对简单的方法,不知道能不能帮到你删除:procedure TForm1.Button1Click(Sender: TObject);begin deletefile('c:\123.txt') ...
- Unity3D 事件
unity3d事件函数整理,事件,回调函数,消息处理 Unity3D中所有控制脚本的基类MonoBehaviour有一些虚函数用于绘制中事件的回调,也可以直接理解为事件函数,例如大家都很清楚的Star ...
- OC中copy的使用
@property内存管理策略的选择 1.非ARC 1> copy : 只用于NSString\block: 2> retain : 除NSString\block以外的OC对象: 3&g ...
- 尚学堂Spring视频教程(七):AOP XML
此处省略N个字.... 直接看下面 推荐链接: Spring Aop实例之xml配置
- 使用BigDecimal进行精确运算
首先我们先来看如下代码示例: 1 public class Test_1 { 2 public static void main(String[] args) { 3 System.out.print ...
- JavaScript笔记:变量及其作用域
一.变量的定义及声明 在javascript中变量仅仅是用来保存值的一个占位符而已,定义变量时要使用关键字var后跟一个变量名,如下所示: var message; //定义一个变量message,像 ...
- css3动画3
1.transition过渡动画 2.@keyframes关键帧动画,配合transform.animation使用
- ps基础知识
一 1. ps常用快捷键:ctrl+d 结束选区 ctrl+alt+z 返回 ctrl+z 撤销 ctrl+x 剪切 ctrl+t 编辑图片 ctr ...