引用新浪天气预报http://community.youkuaiyun.com/

抓取新浪天气数据
本文介绍了一种使用C#从新浪天气网站抓取天气信息的方法。通过创建HTTP请求并设置必要的参数,文章详细展示了如何获取指定网页的内容,进一步解析HTML以提取具体的天气信息。

private void Page_Load(object sender, System.EventArgs e)
 {
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://weather.sina.com.cn/iframe/weather/210201_w.html");
  request.Method = "Get";
  request.ContentType = "application/x-www-form-urlencoded";
  WebResponse response = request.GetResponse();
  Stream s = response.GetResponseStream();
  StreamReader sr = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
  string html = sr.ReadToEnd();
  s.Close();
  sr.Close();

  int start = html.IndexOf("<br>");
  html = html.Substring(start + 4);

  int end = html.IndexOf("</td>");
  html = html.Substring(0,end);

  htmResult = html;

}

PS C:\Windows\system32> iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occ urred on a send." At line:1 char:1 + iex ((New-Object System.Net.WebClient).DownloadString('https://commun ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException PS C:\Windows\system32> # 临时允许脚本执行(仅限当前进程) PS C:\Windows\system32> Set-ExecutionPolicy Bypass -Scope Process -Force PS C:\Windows\system32> [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) WARNING: Files from a previous installation of Chocolatey were found at 'C:\ProgramData\chocolatey'. WARNING: An existing Chocolatey installation was detected. Installation will not continue. This script will not overwrite existing installations. If there is no Chocolatey installation at '', delete the folder and attempt the installation again. Please use choco upgrade chocolatey to handle upgrades of Chocolatey itself. If the existing installation is not functional or a prior installation did not complete, follow these steps: - Backup the files at the path listed above so you can restore your previous installation if needed. - Remove the existing installation manually. - Rerun this installation script. - Reinstall any packages previously installed, if needed (refer to the lib folder in the backup). Once installation is completed, the backup folder is no longer needed and can be deleted. PS C:\Windows\system32> # 检查服务器支持的协议 PS C:\Windows\system32> $url = "https://community.chocolatey.org" PS C:\Windows\system32> [System.Net.ServicePointManager]::FindServicePoint($url).Address AbsolutePath : / AbsoluteUri : https://community.chocolatey.org/ LocalPath : / Authority : community.chocolatey.org HostNameType : Dns IsDefaultPort : True IsFile : False IsLoopback : False PathAndQuery : / Segments : {/} IsUnc : False Host : community.chocolatey.org Port : 443 Query : Fragment : Scheme : https OriginalString : https://community.chocolatey.org DnsSafeHost : community.chocolatey.org IdnHost : community.chocolatey.org IsAbsoluteUri : True UserEscaped : False UserInfo : PS C:\Windows\system32> # 检查系统代理设置 PS C:\Windows\system32> [System.Net.WebRequest]::GetSystemWebProxy().GetProxy($url) AbsolutePath : / AbsoluteUri : https://community.chocolatey.org/ LocalPath : / Authority : community.chocolatey.org HostNameType : Dns IsDefaultPort : True IsFile : False IsLoopback : False PathAndQuery : / Segments : {/} IsUnc : False Host : community.chocolatey.org Port : 443 Query : Fragment : Scheme : https OriginalString : https://community.chocolatey.org DnsSafeHost : community.chocolatey.org IdnHost : community.chocolatey.org IsAbsoluteUri : True UserEscaped : False UserInfo :
最新发布
09-22
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值