LoginSignup
2
0

mindの研究 その78

Posted at

概要

mindが、謎なので調べてみた。
練習問題やってみた。

練習問題

mindで、QiitaのuserのContributionを取れ。

方針

HttpGetは、Vbsの力を借りる。
正規表現も、Vbsの力を借りる。
msgboxも、Vbsの力を借りる。

サンプルコード


出力ファイルは ファイル。

メインとは
 「scra.vbs」で 出力ファイルを 新規オープンし
 「Function Scraping(url)」で 出力ファイルに 一行書き込み
 「	SamAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"」で 出力ファイルに 一行書き込み
 「	Set objHTTP = CreateObject("Microsoft.XMLHTTP")」で 出力ファイルに 一行書き込み
 「	objHTTP.Open "GET", url, False」で 出力ファイルに 一行書き込み
 「	objHTTP.SetRequestHeader "User-Agent", SamAgent」で 出力ファイルに 一行書き込み
 「	objHTTP.Send」で 出力ファイルに 一行書き込み
 「	Set objStream = CreateObject("ADODB.Stream")」で 出力ファイルに 一行書き込み
 「	objStream.Type = 1」で 出力ファイルに 一行書き込み
 「	objStream.Open」で 出力ファイルに 一行書き込み
 「	objStream.Write objHTTP.responseBody」で 出力ファイルに 一行書き込み
 「	objStream.Position = 0」で 出力ファイルに 一行書き込み
 「	objStream.Type = 2」で 出力ファイルに 一行書き込み
 「	objStream.Charset = "utf-8"」で 出力ファイルに 一行書き込み
 「	http_source = objStream.ReadText」で 出力ファイルに 一行書き込み
 「	objStream.Close」で 出力ファイルに 一行書き込み
 「	Set re = New RegExp」で 出力ファイルに 一行書き込み
 「	re.Pattern = "Contribution: ([0-9].+[0-9]) "」で 出力ファイルに 一行書き込み
 「	re.IgnoreCase = True」で 出力ファイルに 一行書き込み
 「	re.Global = True」で 出力ファイルに 一行書き込み
 「	Set Matches = re.Execute(http_source)」で 出力ファイルに 一行書き込み
 「	For Each Match in Matches」で 出力ファイルに 一行書き込み
 「		RetStr = RetStr && Match.submatches(0) && " です。" && vbCRLF」で 出力ファイルに 一行書き込み
 「	Next」で 出力ファイルに 一行書き込み
 「	msgbox RetStr」で 出力ファイルに 一行書き込み
 「	Set re = Nothing」で 出力ファイルに 一行書き込み
 「	Set Matches = Nothing」で 出力ファイルに 一行書き込み
 「	Set objHTTP = Nothing」で 出力ファイルに 一行書き込み
 「	Set objStream = Nothing」で 出力ファイルに 一行書き込み
 「End Function」で 出力ファイルに 一行書き込み
 「Scraping("https://qiita.com/ohisama@github")」で 出力ファイルに 一行書き込み
 出力ファイルを クローズし
 「C:\Windows\SysWOW64\cscript scra.vbs」を プログラム実行する
。





実行結果

image.png

以上。

2
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
2
0