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++程序员求职面试指导,而旨在从技术上分析面试题的内涵.文中的大多数面试题来自各大论坛,部分试题解答也参考了网友的意见. 许多面试题看似简单,却需要深厚的基 ...
随机推荐
- Jenkins若干小问题
1. Jenkins上不能直接在shell中调用scp命令来执行上传下载操作,核心问题是scp需要输入密码. 为了可以直接将密码传递过去.我们安装 sshpass 来透传密码 a. 安装sshpas ...
- maven 记录
1. Can't find parent: 工程中的pom.xml中定义的”project -> version”或者”parent project -> version”设置的不对导致 ...
- json&pickle&xml
json .dumps() 变成 json 的字符串 import json dic={"name":"alex"} data=json.dumps(di ...
- SQL 常用的命令 (转)
地址:http://www.cnblogs.com/longly/p/6030609.html 设置SQL语句所用的字符编码:set names UTF8; 判断指定的数据库是否存在:DROP DAT ...
- php 对url 操作类:url拼接、get获取页面、post获取页面(带传参)
/* * @brief url封装类,将常用的url请求操作封装在一起 * */ class URL{ private $error; public function __construct(){ $ ...
- ArcGIS Engine中数据的加载 (转)
1.加载Shapefile数据 1 IWorkspaceFactory pWorkspaceFactory; 2 IFeatureWorkspace pFeatureWorkspace; 3 IFea ...
- java获取文件夹下文件名
public static String [] getFileName(String path) { File file = new File(path); String [] fileName = ...
- 创建一个List获取数据的lookup
第一步,在类:syslookup中新建方法 public static client void lookupList(FormStringControl _formStringControl, Lis ...
- UIPopoverController使用
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- 转:SAAS 测试
基于SaaS云计算网络性能测试指标研究 来源:中国软件评测中心 作者:马子明 投稿时间:2011-04-02 1.基于SaaS的云计算 SaaS(Software as a Service,软件即 ...