Sub foo() Set httpReq = CreateObject("MSXML2.XMLHTTP") httpReq.Open "GET", "https://www.yahoo.co.jp/", False httpReq.Send Set httpReq2 = CreateObject("MSXML2.XMLHTTP") httpReq2.Open "GET", "https://urasunday.com/", False httpReq2.Send
Do flg = False If httpReq.readyState < 4 Then flg = True If httpReq2.readyState < 4 Then flg = True DoEvents Loop While flg
Set HTML = CreateObject("htmlfile") HTML.write httpReq.responsetext Set HTML2 = CreateObject("htmlfile") HTML2.write httpReq.responsetext End Sub 0140デフォルトの名無しさん2019/03/23(土) 00:08:10.78ID:GJYnZjvR If httpReq.readyState < 4 Then flg = True If httpReq2.readyState < 4 Then flg = True 片方で抜ける 配列ぐらい使えよ 0141デフォルトの名無しさん2019/03/23(土) 00:23:31.53ID:GJYnZjvR 読み込めた物から処理するんだよ 0142デフォルトの名無しさん2019/03/23(土) 00:41:36.68ID:sBAP9hOD>>140 ・普通に逆だった、スマン ・pushくれ。redimしなくていい素直なpush ・なんかテキトーにやってもうまいことやってくれる非同期欲しい ・eachで自動生成されるindexくれ ・インクリメントくれ ってことでうんこコードになったわ、すまん
Dim httpReq(max_count) index_httpReq = 0 For Each url_foo In url_arr Set httpReq(index_httpReq) = CreateObject("MSXML2.XMLHTTP") httpReq(index_httpReq).Open "GET", url_foo, False httpReq(index_httpReq).Send index_httpReq = index_httpReq + 1 Next 0144デフォルトの名無しさん2019/03/23(土) 00:42:09.03ID:sBAP9hOD Do flg = False For Each url_foo In url_arr ' どれかがまだ If httpReq(index_foo).readyState < 4 Then flg = True Next DoEvents Loop While flg
Dim html(max_count) index_html = 0 For Each url_foo In url_arr Set html(index_html) = CreateObject("htmlfile") html(index_html).write httpReq(index_html).responsetext Cells(index_html + 1, 1).Value = httpReq(index_html).responsetext 'テスト。A列に出力する index_html = index_html + 1 Next
End Sub 0145デフォルトの名無しさん2019/03/23(土) 00:45:06.99ID:sBAP9hOD>>143までは問題ないと思う >>144でグダグダになった。 パフォーマンス的にはそんなに変わらんだろう。大量にあるとメモリにも影響してきそうだけど 0146デフォルトの名無しさん2019/03/23(土) 01:11:21.36ID:GJYnZjvR If httpReq(index_foo).readyState < 4 Then flg = True コレじゃ1つでも読み込めたらループから抜ける set したのはリリースする
処理がおもいのは html(index_html).write httpReq(index_html).responsetext これだろ 0147デフォルトの名無しさん2019/03/23(土) 01:15:54.12ID:GJYnZjvR 同じ個数配列で使うものはTypeを使って構造体にしろよ 構造体を配列で取る redimぐらい使えよ 0148デフォルトの名無しさん2019/03/23(土) 01:39:28.59ID:sBAP9hOD>>144 Do flg = False For Each url_foo In url_arr ' どれかがまだ If httpReq(index_foo).readyState < 4 Then flg = True Next DoEvents Loop While flg ↓ For Each url_foo In url_arr ' どれかがまだ Do flg = False If httpReq(index_foo).readyState < 4 Then flg = True DoEvents Loop While flg Next
>>161 やっぱり難しいよな >全ての配列が処理出来たら終わればいいぐらいのコーディングだな これで書いたよ DOM部分はどうせ瞬殺だからまとめて良い 0163デフォルトの名無しさん2019/03/23(土) 12:12:55.71ID:/daUWZWt>>162 他の言語で簡単にかけるって言っても 所詮その言語で提供されたルーチンを使うだけだから 適した言語で書けば比較的簡単にかけることは確か コーディングに関しては直感で書いたからもう少し読んでみよう 0164デフォルトの名無しさん2019/03/23(土) 12:16:35.94ID:/daUWZWt まあ、所詮夜勤から帰って書き込みしてるから 午後は、お酒が進むんでまあ気にするな 0165デフォルトの名無しさん2019/03/23(土) 12:44:05.74ID:4ZM/hDcb>>157 > コールバックの部分だけはマジで分からんかった > どうやって書くんだ コールバックなんていらんだろ 素直にreadyStateが4になったら処理すればいいだけ スマホから打ってるからデバッグしてないけどこんな感じ Type Request Session As Object Done As Boolean End Type url_arr = Array("https://www.yahoo.co.jp/", "https://urasunday.com/") Dim Requests() ReDim Requests(LBound(url_arr) To UBound(url_arr)) Dim Index As Integer For Index = LBound(url_arr) To UBound(url_arr) With Requests(Index) Set .Session = CreateObject("MSXML2.XMLHTTP") .Session.Open "GET", url_arr(Index), False .Session.Send .Done = False End With Next ' 続く… 0166デフォルトの名無しさん2019/03/23(土) 12:44:29.37ID:4ZM/hDcb ' 続き Dim AllDone As Boolean Do AllDone = True For Index = LBound(url_arr) To UBound(url_arr) With Requests(Index) If Not .Done Then If .Session.readyState < 4 Then AllDone = False Else Cells(Index + 1, 1).Value = .responseText .Done = True End If End If End With Next DoEvents Until AllDone 0167デフォルトの名無しさん2019/03/23(土) 14:51:45.33ID:uLwnX5A6>>160 いや、だから... それに>>67じゃなくて>>69だろ。