您如何检测链接. [英] How do you detect link.

查看:81
本文介绍了您如何检测链接.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想启动一个个人链接交换程序,一个人可以将我的链接放置在他们的站点上,并将他们的链接放置在我的站点上.如果他们指定要放置链接的页面,我想知道如何在网站上检测链接.谢谢.

I want to start a personal link exchange program where a person can place my link on their site and I will place their link on mine . I would like to know how to detect the link on a website if they specify the page where the link is going to be placed Thanks in advance.

推荐答案

可能最快一种方法是从它们提供的URL解析HTML,然后对它运行string.Contains(string)以检查是否存在您希望在其中看到的内容.
例如

Probably the quickest way would be to parse the HTML from the URL they provide, and then run a string.Contains(string) against it to check for the existence of whatever you expect to see there.
eg

string link = "http://example.com/example";
string url = "http://otherperson.com/page/where/your/link/is";
string pageContents = getPageContents(url);
bool isThere = pageContents.Contains(link);
public string getPageContents(string url) {
	HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
	using (Stream stream = request.GetResponse().GetResponseStream()) {
		using (StreamReader reader = new StreamReader(stream)) {
			string response = reader.ReadToEnd();
			return response;
		}
	}
}



**这不会确认该链接是可见的还是可行的,因为在注释掉的部分中添加URL仍会返回肯定的结果.



** This will not confirm that the link is visible or viable, as having the URL in a commented out section will still return a positive.


如果我理解您的问题,那么您希望确定谁将访客吸引到您的网站.您可以使用引荐网址,甚至可以给链接伙伴唯一的ID,它们可以通过参数传递给您.例如:somedomain/somepage.aspx?refid = 9065(其中9065标识链接的来源).
If I understand your question, you want to identify who referred a visitor to your site. You can use either the referring URL or you can even give your link-companions unique IDs which they can pass to you through a parameter. Example: somedomain/somepage.aspx?refid=9065 (where 9065 identifies who the link''s coming from).


ctwi001的答案是检索网站内容的好方法.但是也有一种简单的方法.

或者可以使用webclient类. WebClient wc=new WebClicnt(); string content=wc.DownloadString(urlPath);.干杯
ctwi001''s answer is good one to retrieve the website content. But there is a simple way too.

Alternatively can use webclient class. WebClient wc=new WebClicnt(); string content=wc.DownloadString(urlPath);. Cheers


这篇关于您如何检测链接.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆