我正在尝试使用Visual Studio 2015中的C#来检索控制台,或者通过<div>
在.HTML文件中获取ID="show"
的值。
这是我的C#代码
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main()
{
// Create a request for the URL.
WebRequest request = WebRequest.Create("http://localhost:8080/trymyown/computeArea.html");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
Console.ReadLine();
}
}
}
这是我的.HTML文件:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>computeArea</title>
</head>
<body>
<div id="show"> </div>
<script>
// This example creates a simple polygon representing the Bermuda Triangle.
// When the user clicks on the polygon an info window opens, showing
// information about the polygon's coordinates.
var map;
var build;
function initMap() {
// Define the LatLng coordinates for the polygon.
var RoundList = [
{lat: 25.774, lng: -80.190},
{lat: 18.466, lng: -66.118},
{lat: 18.400, lng: -65.118},
{lat: 19.551, lng: -60.164},
{lat: 32.321, lng: -64.757}
];
// Construct the polygon.
build = new google.maps.Polygon({
paths: RoundList
});
}
function showArea()
{
var area = parseFloat(google.maps.geometry.spherical.computeArea(build.getPath())) * 0.000247105; //this
area = area.toFixed(4);
document.getElementById("show").innerHTML = area;
console.log(area);
//document.write("Area = ");
//document.write(area);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCVK8oA9vvEBK0CSSvD8haB5i1QYreHmmA&callback=initMap"></script>
<script>
setTimeout(function(){ showArea(); }, 100);
</script>
</body>
</html>
但我遇到了一些问题! 我只能获得所有HTML“代码”。
有人可以帮我解决一下吗?
答案 0 :(得分:0)
我不确定我是否正确理解了这个问题,但我认为您想要提取div的内容,请使用以下内容:
MyApp.instance
希望这是你正在寻找的。 p>