解析搜索引擎关键词

发布于 2024-09-28 02:19:57 字数 1059 浏览 0 评论 0原文

我试图找到最有效的方法来解析我的 System.Web.HTTPRequest.UrlReferrer,以找到用于将访问者吸引到我的网站的搜索词(假设他们通过搜索引擎结果页面到达我的网站)。

我想(希望)我会使用 HttpUtility.ParseQueryString 方法,但我的问题在于试图找出要解析的变量。我有以下需要检查的清单。该列表显示了搜索引擎和每个搜索引擎使用的参数。

daum:q,
eniro:search_word,
naver:query,
images.google:q,
google:q,
yahoo:p,
msn:q,
bing:q,
aol:query,
aol:encquery,
lycos:query,
ask:q,
altavista:q,
netscape:query,
cnn:query,
about:terms,
mamma:query,
alltheweb:q,
voila:rdata,
virgilio:qs,
live:q,
baidu:wd,
alice:qs,
yandex:text,
najdi:q,
aol:q,
mama:query,
seznam:q,
search:q,
wp:szukaj,
onet:qt,
szukacz:q,
yam:k,
pchome:q,
kvasir:q,
sesam:q,
ozu:q,
terra:query,
mynet:q,
ekolay:q,
rambler:words

因此,虽然我可以仔细检查每一个并说一些类似

NameValueCollection query = HttpUtility.ParseQueryString(UrlReferrer);
var referrer = Request.UrlReferrer.ToString();

if(referrer.Contains("google.com")
     return (query["q"]);
else if(referrer.Contains("yahoo.com")
     return (query["p"]);

我认为必须有更好的方法,因为我有这个很好的名称/值对来工作,以及 ParseQueryString 方法的强大功能,但我却一片空白。

I am trying to find the most effective way to parse my System.Web.HTTPRequest.UrlReferrer to find the search term that was used to drive the visitor to my site assuming they arrived at my site via a search engine results page.

I am thinking (hoping) I'd use the HttpUtility.ParseQueryString method, but my problem comes in trying to figure out what variable to parse for. I have the following list that I am required to check for. The list shows the search engine and the param that each uses.

daum:q,
eniro:search_word,
naver:query,
images.google:q,
google:q,
yahoo:p,
msn:q,
bing:q,
aol:query,
aol:encquery,
lycos:query,
ask:q,
altavista:q,
netscape:query,
cnn:query,
about:terms,
mamma:query,
alltheweb:q,
voila:rdata,
virgilio:qs,
live:q,
baidu:wd,
alice:qs,
yandex:text,
najdi:q,
aol:q,
mama:query,
seznam:q,
search:q,
wp:szukaj,
onet:qt,
szukacz:q,
yam:k,
pchome:q,
kvasir:q,
sesam:q,
ozu:q,
terra:query,
mynet:q,
ekolay:q,
rambler:words

So while I could go through each and say something like

NameValueCollection query = HttpUtility.ParseQueryString(UrlReferrer);
var referrer = Request.UrlReferrer.ToString();

if(referrer.Contains("google.com")
     return (query["q"]);
else if(referrer.Contains("yahoo.com")
     return (query["p"]);

I'm thinking there must be a better way since I have this nice name/value pair to work against,and the power of the ParseQueryString method, but I'm drawing a blank.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雅心素梦 2024-10-05 02:19:57

嗯,我对此并不满意,而且我认为我没有实现效率,但这就是我最终所做的。我仍然很想听到你们提出更好的方法。

private string GetKeywords(string urlReferrer)
    {
        var searchQuery = string.Empty;
        var url = new Uri(urlReferrer);
        var query = HttpUtility.ParseQueryString(urlReferrer);
        switch (url.Host)
        {
            case "google":
            case "daum":
            case "msn":
            case "bing":
            case "ask":
            case "altavista":
            case "alltheweb":
            case "live":
            case "najdi":
            case "aol":
            case "seznam":
            case "search":
            case "szukacz":
            case "pchome":
            case "kvasir":
            case "sesam":
            case "ozu":
            case "mynet":
            case "ekolay":
                searchQuery = query["q"];
                break;
            case "naver":
            case "netscape":
            case "mama":
            case "mamma":
            case "terra":
            case "cnn":
                searchQuery = query["query"];
                break;
            case "virgilio":
            case "alice":
                searchQuery = query["qs"];
                break;
            case "yahoo":
                searchQuery = query["p"];
                break;
            case "onet":
                searchQuery = query["qt"];
                break;
            case "eniro":
                searchQuery = query["search_word"];
                break;
            case "about":
                searchQuery = query["terms"];
                break;
            case "voila":
                searchQuery = query["rdata"];
                break;
            case "baidu":
                searchQuery = query["wd"];
                break;
            case "yandex":
                searchQuery = query["text"];
                break;
            case "szukaj":
                searchQuery = query["wp"];
                break;
            case "yam":
                searchQuery = query["k"];
                break;
            case "rambler":
                searchQuery = query["words"];
                break;
            default:
                searchQuery = query["q"];
                break;
        }
        return searchQuery;
    }

Well, I am not happy with it, and I don't think I achieved efficiency, but this is what I ended up doing. I'd still love to hear from you guys with better approaches.

private string GetKeywords(string urlReferrer)
    {
        var searchQuery = string.Empty;
        var url = new Uri(urlReferrer);
        var query = HttpUtility.ParseQueryString(urlReferrer);
        switch (url.Host)
        {
            case "google":
            case "daum":
            case "msn":
            case "bing":
            case "ask":
            case "altavista":
            case "alltheweb":
            case "live":
            case "najdi":
            case "aol":
            case "seznam":
            case "search":
            case "szukacz":
            case "pchome":
            case "kvasir":
            case "sesam":
            case "ozu":
            case "mynet":
            case "ekolay":
                searchQuery = query["q"];
                break;
            case "naver":
            case "netscape":
            case "mama":
            case "mamma":
            case "terra":
            case "cnn":
                searchQuery = query["query"];
                break;
            case "virgilio":
            case "alice":
                searchQuery = query["qs"];
                break;
            case "yahoo":
                searchQuery = query["p"];
                break;
            case "onet":
                searchQuery = query["qt"];
                break;
            case "eniro":
                searchQuery = query["search_word"];
                break;
            case "about":
                searchQuery = query["terms"];
                break;
            case "voila":
                searchQuery = query["rdata"];
                break;
            case "baidu":
                searchQuery = query["wd"];
                break;
            case "yandex":
                searchQuery = query["text"];
                break;
            case "szukaj":
                searchQuery = query["wp"];
                break;
            case "yam":
                searchQuery = query["k"];
                break;
            case "rambler":
                searchQuery = query["words"];
                break;
            default:
                searchQuery = query["q"];
                break;
        }
        return searchQuery;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文