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++程序员求职面试指导,而旨在从技术上分析面试题的内涵.文中的大多数面试题来自各大论坛,部分试题解答也参考了网友的意见. 许多面试题看似简单,却需要深厚的基 ...
随机推荐
- 前端 动态表单提交(post、put)
第一步:form表单定义统一属性 <input type="text" class="form-value" /> 第二步:获取所有值 var fo ...
- DHTMLX-第一弹
DHTMLX 半年前结束了漂泊的工作生活回到了公司,跟着团队开发新产品.忙碌起来就很少有时间静下来好好写点东西.公司既然要开发新的产品当然也会接触一些新的东西,也会面临新的挑战.接下来就将项目前端所用 ...
- JDBC连接实例
package com.javaee.corejava; import java.sql.Connection; import java.sql.DriverManager; import java. ...
- MyBatis与Spring整合
1.单独使用MyBatis 单独使用MyBatis,不结合其他框架,主要步骤是: 1.创建SqlSessionFactory对象 创建方法是通过SqlSessionFactoryBuilder这个类从 ...
- 挖掘微信Web版通信的全过程 [转]
昨天是周末,在家闲得无聊,于是去weiphone.com逛了一圈,偶然发现有人发了一帖叫<微信 for Mac>, 这勾起了我的好奇心,国内做Mac开发的人确实很少,对于那些能够独自开发一 ...
- The server encountered an internal error that prevented it from fulfilling this request.
type Exception report message Request processing failed; nested exception is org.mybatis.spring.MyBa ...
- json转换
Newtonsoft.Json.JsonConvert.SerializeObject 使用上述语句,将创建的对象, 转换成json格式
- Jquery实现兼容各大浏览器的Enter回车切换输入焦点的方法
<script type="text/javascript"> $('input:text:first').focus(); document.onkeydown = ...
- C++设计模式-TemplateMethod模板方法模式
Template模板方法模式作用:定义一个操作中的算法的骨架.而将一些步骤延迟到子类中,模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 其关键是将通用算法(逻辑)封装在抽象基 ...
- 在大于32GB或64GB容量的SD卡上使用NOOB安装树莓派 - Using NOOB on SD cards larger than 32GB or 64GB for Raspberry Pi
在树莓派上玩了一小段时间了,因为装的软件包越来越多,所以越来越感觉16G的SD卡没办法长期使用下去.于是采购了几张64G的SD卡,打算周末装上系统.可是按照一般的流程,在Windows下用SD For ...