<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBA: Доступ к элементу div страницы на html посредством VBA]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=17703</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17703&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBA: Доступ к элементу div страницы на html посредством VBA».]]></description>
		<lastBuildDate>Tue, 28 Mar 2023 06:48:26 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: VBA: Доступ к элементу div страницы на html посредством VBA]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=157394#p157394</link>
			<description><![CDATA[<p><strong>AleksP</strong>,</p><div class="codebox"><pre><code>
Dim sUrl, oHttpRequest, oDocument, oElement
sUrl = &quot;https://synapsenet.ru/zakupki/fz223/32312204305%231--sanktpeterburg-vipolnenie-rabot-po-obsledovaniyu-stroitelnih&quot;
Set oHttpRequest = CreateObject(&quot;WinHttp.WinHttpRequest.5.1&quot;)
With oHttpRequest
	.Open &quot;GET&quot;, sUrl, false
	.Send
	Set oDocument = CreateObject(&quot;htmlfile&quot;)
	With oDocument
		&#039; Более безопасный парсинг тела документа
		.designMode = &quot;on&quot;
		.open
		.write oHttpRequest.ResponseText
		.close
	End With
	For Each oElement in oDocument.all.tags(&quot;div&quot;)
		If InStr(1,oElement.className,&quot;tct-tender-text&quot;,vbTextCompare) &gt; 0 Then
			MsgBox oElement.innerText
			Exit For
		End if
	Next
End With
</code></pre></div><p>Как альтернатива, если на машине <span class="bbu">точно</span> установлен IE выше семёрки, можно инициализировать документ в режиме более высокой версии и тогда будут доступны методы <strong>querySelectorAll</strong> и <strong>getElementsByClassName</strong></p>]]></description>
			<author><![CDATA[null@example.com (Xameleon)]]></author>
			<pubDate>Tue, 28 Mar 2023 06:48:26 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=157394#p157394</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBA: Доступ к элементу div страницы на html посредством VBA]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=157254#p157254</link>
			<description><![CDATA[<p><strong>AleksP</strong>, добро пожаловать на форум! Ознакомьтесь, пожалуйста, с <a href="https://forum.script-coding.com/misc.php?action=rules">Правилами</a>, отредактируйте свой пост. Обратите внимание на оформление <a href="https://forum.script-coding.com/misc.php?action=rules#code-formatting">кода</a>.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 19 Mar 2023 13:18:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=157254#p157254</guid>
		</item>
		<item>
			<title><![CDATA[VBA: Доступ к элементу div страницы на html посредством VBA]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=157240#p157240</link>
			<description><![CDATA[<p>Добрый день!</p><p>В html коде есть элемент div, к которому необходимо получить доступ посредством VBA<br /></p><div class="codebox"><pre><code>
   &lt;div id=&quot;tender-card-content&quot;&gt;
                    &lt;div id=&quot;report-script&quot; class=&quot;tender-card-title&quot;&gt;
                        &lt;h1 class=&quot;tct-tender-number&quot;&gt;
                            Закупка &lt;span class=&quot;copy-script tender-number-copy&quot;&gt;32312204305&lt;/span&gt;
                        &lt;/h1&gt;
                        &lt;div class=&quot;tct-tender-text&quot;&gt;[b]Содержимое, которое необходимо скопировать с html страницы через VBA[/b]&lt;/div&gt;
...</code></pre></div><p>Получается только через getElementsByTagName(&quot;div&quot;)(номер элемента).innerText, но номер элемента div может меняться динамически и такой вариант не подходит.<br />Привожу код, в котором попробовал разные варианты доступа с указанием сообщения о ошибке в комментариях.</p><div class="codebox"><pre><code>
Sub test()

sURL = &quot;https://synapsenet.ru/zakupki/fz223/32312204305%231--sanktpeterburg-vipolnenie-rabot-po-obsledovaniyu-stroitelnih&quot;

    Set oXMLHTTP = CreateObject(&quot;MSXML2.XMLHTTP&quot;)
    With oXMLHTTP
        .Open &quot;GET&quot;, sURL, False
        .send
        txt = .responseText
        
        Set pDoc = CreateObject(&quot;HTMLFile&quot;)
        pDoc.body.innerHTML = txt
   
       .Open &quot;GET&quot;, sURL, False: .send
        getHTTP = StrConv(.responseBody, vbUnicode)
        
        MsgBox pDoc.getElementsByTagName(&quot;div&quot;)(номер элемента).innerText
        &#039;Работает.&#039;

        MsgBox getHTTP.getElementsByTagName(&quot;div&quot;)(номер элемента).innerText
        &#039;Сообщение об ошибке Object required.&#039;
        
        pDoc.getElementsByClassName (&quot;tct-tender-text&quot;)
        &#039;Сообщение об ошибке Object doesn&#039;t support this property or method.&#039;
        
       getHTTP.getElementsByClassName (&quot;tct-tender-text&quot;)
        &#039;Сообщение об ошибке Object required.&#039;
   
       pDoc.querySelectorAll (&quot;tct-tender-text&quot;)
      &#039;Сообщение об ошибке Object doesn&#039;t support this property or method.&#039;
      
        getHTTP.querySelectorAll (&quot;tct-tender-text&quot;)
        &#039;Сообщение об ошибке Object required.&#039;

    End With
    
    Set oXMLHTTP = Nothing

End Sub</code></pre></div><p>Как нужно исправить код, чтобы получить доступ к нужному элементу?</p>]]></description>
			<author><![CDATA[null@example.com (AleksP)]]></author>
			<pubDate>Sun, 19 Mar 2023 11:15:48 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=157240#p157240</guid>
		</item>
	</channel>
</rss>
