0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

cscの作法 その319

Posted at

概要

cscの作法、調べてみた。
練習問題、やってみた。

練習問題

スクレイピングを、実装せよ。

サンプルコード

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace App 
{
	class test {
		static void Scraping(string url) {
			ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
			Encoding enc = Encoding.GetEncoding("UTF-8");
			WebRequest req = WebRequest.Create(url);
			WebResponse res = req.GetResponse();
			Stream st = res.GetResponseStream();
			StreamReader sr = new StreamReader(st, enc);
			string txt = sr.ReadToEnd();
			sr.Close();
			st.Close();
			Regex re0 = new Regex("<script[^>]*>[^<]+");
			string str0 = re0.Replace(txt, "<***>");
			Regex re1 = new Regex("<(\"[^\"]*\"|'[^']*'|[^'\">])*>");
			string str1 = re1.Replace(str0, "");
			Console.WriteLine(str1);
		}
		static void Main() {
			Scraping("https://blog.qiita.com/");
		}
	}
}



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?