string locationName = Console.ReadLine();
string url = "https://www.google.com/#q=latitude+and+longitude+" + locationName;
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
HtmlNode rateNode = doc.DocumentNode.SelectSingleNode("//div[@class='_XWk']");
string res = rateNode.InnerText;
Console.WriteLine(res);
我使用上面的代碼從谷歌獲取某個位置並將顯示經緯度的文本框複製到字符串res中。每次運行代碼時,我都會收到一個nullReferenceException。將div從一個網站分配到一個字符串
而我怎樣才能將字符串拆分爲兩個字符串與座標只?
String res = "34.0522° N, 118.2437° W"
爲String res1 = "34.0522"
和String res2 = "118.2437"
在此先感謝
非常感謝你,它終於工作了。 –