Webclient and Language

佐手、 提交于 2019-12-24 10:00:23

问题


I want to scrape google suggest in german language:

string url = "http://google.de/complete/search?output=toolbar&q=" + txtResults.Lines[i].Replace(" ", "%20%");
WebClient client = new WebClient();
client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/17.0 Firefox/17.0");
client.Headers.Add("Accept-Encoding:", "gzip, deflate");
client.Headers.Add("Connection:", "keep-alive");
doc.Load(client.OpenRead(url), System.Text.Encoding.UTF8, true);

But i always get international results whereas in the browser i get the german results by the given .de url. So i added the header:

client.Headers.Add("Accept-Language:", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3");

But now i get the error: Specified value has invalid HTTP Header characters

I also tried to set the language of my application by

Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");

but this doens't help either.


回答1:


Try removing the colon (:) from your header name:

client.Headers.Add("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3");


来源:https://stackoverflow.com/questions/13760988/webclient-and-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!