<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Получение элемента из <a href => из IE]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13404&amp;type=atom" />
	<updated>2018-03-16T11:46:11Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=13404</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=124088#p124088" />
			<content type="html"><![CDATA[<p><strong>KusochekDobra</strong><br />Спасибо, опробую и ваш вариант.<br />p.s. я опоздал на 35 секунд )</p>]]></content>
			<author>
				<name><![CDATA[estenha]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33963</uri>
			</author>
			<updated>2018-03-16T11:46:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=124088#p124088</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=124087#p124087" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>estenha пишет:</cite><blockquote><p>Доброго времени суток! Вы не могли бы подсказать на примере вашего кода, который замечательно работает, как реализовать несколько иную задачу...</p></blockquote></div><p>Сделал через <strong><a href="https://autohotkey.com/docs/commands/IfInString.htm">IfInString</a> и Array.Push</strong> (мне к тому же еще нужен именно последний элемент из списка идентичных ссылок.) Если кому интересно:</p><div class="codebox"><pre><code>Larray := []
Needle = hyper-universe-
oIE := ComObjCreate(&quot;InternetExplorer.Application&quot;)
oIE.visible := True
oIE.navigate(&quot;https://www.mmorpg.com/sweepstakes&quot;)
While oIE.busy  
   Sleep, 20
links := oIE.document.links
; MsgBox % links.length
Loop % links.length  {
   link := links[A_Index - 1]
   b := link.href
   IfInString, b, %Needle%
	{
;	  MsgBox, % link.href
	  Larray.Push(link.href)
	}
}
z := Larray.MaxIndex()
MsgBox % &quot;Последний элемент &quot; Larray[z]

; for index, element in Larray ; здесь можно посмотреть, что в массиве
;	{
;		MsgBox % &quot;Element number &quot; . index . &quot; is &quot; . element
;	}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[estenha]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33963</uri>
			</author>
			<updated>2018-03-16T11:40:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=124087#p124087</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=124086#p124086" />
			<content type="html"><![CDATA[<p>По условию, отображаемый текст ссылки должен быть эквивалентен &quot;Hyper Universe&quot; без учёта регистра. Если нужны все ссылки, отображаемый текст которых содержит &quot;Hyper Universe&quot;, можно записать так:<br /></p><div class="codebox"><pre><code>
oIE := ComObjCreate(&quot;InternetExplorer.Application&quot;)
oIE.visible := True
oIE.navigate(&quot;https://www.mmorpg.com/sweepstakes&quot;)
While oIE.busy  
	Sleep, 20
links := oIE.document.links
Loop % links.length  {
	link := links[A_Index - 1]
	if (CheckString(link.innerText, &quot;Hyper Universe&quot;))
		MsgBox, % link.href
}
ExitApp
CheckString(mainStr, srchStr) {
	if mainStr contains %srchStr%
		return true
	return false
}
</code></pre></div><p>Если нужны ссылки только из заголовков к каждой игре, то можно сделать выборку по классу и потом проходить циклом по её результату:<br /></p><div class="codebox"><pre><code>
oIE := ComObjCreate(&quot;InternetExplorer.Application&quot;)
oIE.visible := True
oIE.navigate(&quot;https://www.mmorpg.com/sweepstakes&quot;)
While oIE.busy  
	Sleep, 20
links := oIE.document.querySelectorAll(&quot;.suhlink&quot;)
Loop % links.length  {
	link := links[A_Index - 1]
	if (CheckString(link.innerText, &quot;Hyper Universe&quot;))
		MsgBox, % link.href
}
ExitApp
CheckString(mainStr, srchStr) {
	if mainStr contains %srchStr%
		return true
	return false
}
</code></pre></div><p>Если необходимо искать вхождения &quot;hyper-universe&quot; в тексте ссылки, замените условие:<br /></p><div class="codebox"><pre><code>
if (CheckString(link.innerText, &quot;Hyper Universe&quot;))
</code></pre></div><p>На:<br /></p><div class="codebox"><pre><code>
if (CheckString(link.href, &quot;hyper-universe&quot;))
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2018-03-16T11:40:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=124086#p124086</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=124080#p124080" />
			<content type="html"><![CDATA[<p>Доброго времени суток! Вы не могли бы подсказать на примере вашего кода, который замечательно работает, как реализовать несколько иную задачу - необходимо на основе подстроки из link.href выбирать определенные ссылки, т.е. в данном вашем коде и примере с сайта нужно находить, возьмем тот же Hyper Universe, в атрибуте href=&quot;/sweepstakes/hyper-universe-mvp-starter-pack-sweepstakes-1000000057&quot; подстроку hyper-universe, и выводить полную ссылку с этой подстрокой в тот же MsgBox. Я пробовал использовать <strong>if Var contains MatchList</strong> - <strong>if link.href contains hyper-universe</strong>, но в этом случае выводятся все ссылки подряд. Видимо, по неопытности я чего-то еще не понимаю.</p><div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>У меня работает:<br /></p><div class="codebox"><pre><code>oIE := ComObjCreate(&quot;InternetExplorer.Application&quot;)
oIE.visible := True
oIE.navigate(&quot;https://www.mmorpg.com/sweepstakes&quot;)
While oIE.busy  
   Sleep, 20
links := oIE.document.links
Loop % links.length  {
   link := links[A_Index - 1]
   if (link.innerText = &quot;Hyper Universe&quot;)
      MsgBox, % link.href
}</code></pre></div></blockquote></div>]]></content>
			<author>
				<name><![CDATA[estenha]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33963</uri>
			</author>
			<updated>2018-03-16T03:05:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=124080#p124080</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=124073#p124073" />
			<content type="html"><![CDATA[<p><strong>KusochekDobra</strong><br />Спасибо. Все работает хорошо.</p>]]></content>
			<author>
				<name><![CDATA[romzes96]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38749</uri>
			</author>
			<updated>2018-03-15T17:56:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=124073#p124073</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=124044#p124044" />
			<content type="html"><![CDATA[<p>Замените в примере, строку:<br /></p><div class="codebox"><pre><code>MsgBox, % href ? href : &quot;Не найдено&quot;</code></pre></div><p>На:<br /></p><div class="codebox"><pre><code>
if (href)
	activlink := href
else
	MsgBox, Не найдено.
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2018-03-14T10:49:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=124044#p124044</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=124043#p124043" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Тогда так примерно:<br /></p><div class="codebox"><pre><code>linkText := &quot;Dsaasd&quot;

oIE := WBGet()
if !IsObject(oIE)  {
   MsgBox, Не удалось получить объект InternetExplorer
   return
}
links := oIE.document.links, href := &quot;&quot;
Loop % links.length  {
   link := links[A_Index - 1]
   if (link.innerText = linkText &amp;&amp; href := link.href)
      break
}
MsgBox, % href ? href : &quot;Не найдено&quot;

WBGet(WinTitle := &quot;ahk_class IEFrame&quot;, Svr# := 1)
{
   static msg := DllCall(&quot;RegisterWindowMessage&quot;, Str, &quot;WM_HTML_GETOBJECT&quot;)
        , IID_IWebBrowserApp := &quot;{0002DF05-0000-0000-C000-000000000046}&quot;
        , IID_IHTMLDocument2 := &quot;{332C4425-26CB-11D0-B483-00C04FD90119}&quot;
        , VT_DISPATCH := 9, F_OWNVALUE := 1
        
   SendMessage, msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   lResult := ErrorLevel
   if (lResult = &quot;FAIL&quot;)
      return
   
   VarSetCapacity(GUID, 16, 0)
   DllCall(&quot;ole32\CLSIDFromString&quot;, WStr, IID_IHTMLDocument2, Ptr, &amp;GUID)
   DllCall(&quot;oleacc\ObjectFromLresult&quot;, Ptr, lResult, Ptr, &amp;GUID, Ptr, 0, PtrP, pdoc)
   oWb := ComObject(VT_DISPATCH, ComObjQuery(pdoc, IID_IWebBrowserApp, IID_IWebBrowserApp), F_OWNVALUE)
   ObjRelease(pdoc)
   return oWb
}</code></pre></div></blockquote></div><p>Здравствуйте. Воспользовался Вашим кодом. для моих целей работает превосходно. Но не могу понять как сделать так что бы в конце не выпрыгивало окно с ссылкой. не могли бы Вы помочь разобраться? Хотелось бы что бы ссылка просто записывалась в переменную допустим <strong>activlink</strong>. Но что бы не было этого окна по завершению скрипта. Но что бы осталось окно о том что ссылка не найдена.</p>]]></content>
			<author>
				<name><![CDATA[romzes96]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38749</uri>
			</author>
			<updated>2018-03-14T09:39:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=124043#p124043</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123419#p123419" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>document.getElementsByClassName(&quot;contestopen&quot;)[0].getElementsByTagName(&quot;a&quot;)[0].href</code></pre></div><p>Также можно через QuerySelectorAll либо XPath, почитайте информацию сами если заинтересует.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-01-26T20:31:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123419#p123419</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123418#p123418" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong>, при вводе этого:<br /></p><div class="codebox"><pre><code>document.getElementsByClassName(&quot;contestopen&quot;)[0].cells[1].links</code></pre></div><p>выводит undefined</p>]]></content>
			<author>
				<name><![CDATA[Alex_Lexon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32135</uri>
			</author>
			<updated>2018-01-26T20:01:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123418#p123418</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123413#p123413" />
			<content type="html"><![CDATA[<p>А в чем проблема? Приведите код.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-01-26T19:12:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123413#p123413</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123410#p123410" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong>, да, этот код действительно работает! Спасибо.<br />А если мне нужно вывести ссылки из getElementsByClassName, то тогда как? Ибо если пробую после класса ставить .links, то выдаёт - undefined.</p>]]></content>
			<author>
				<name><![CDATA[Alex_Lexon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32135</uri>
			</author>
			<updated>2018-01-26T18:33:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123410#p123410</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123406#p123406" />
			<content type="html"><![CDATA[<p>У меня работает:<br /></p><div class="codebox"><pre><code>oIE := ComObjCreate(&quot;InternetExplorer.Application&quot;)
oIE.visible := True
oIE.navigate(&quot;https://www.mmorpg.com/sweepstakes&quot;)
While oIE.busy  
   Sleep, 20
links := oIE.document.links
Loop % links.length  {
   link := links[A_Index - 1]
   if (link.innerText = &quot;Hyper Universe&quot;)
      MsgBox, % link.href
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-01-26T17:39:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123406#p123406</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123392#p123392" />
			<content type="html"><![CDATA[<p>Не работает данный способ, возможно, Вы не совсем поняли, про какие ссылки я говорю.</p>]]></content>
			<author>
				<name><![CDATA[Alex_Lexon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32135</uri>
			</author>
			<updated>2018-01-26T14:28:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123392#p123392</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123384#p123384" />
			<content type="html"><![CDATA[<p>Ссылки находятся во фрейме:<br /></p><div class="codebox"><pre><code>oIE := ComObjCreate(&quot;InternetExplorer.Application&quot;)
oIE.visible := True
oIE.navigate(&quot;https://www.mmorpg.com/sweepstakes&quot;)
While oIE.busy  
   Sleep, 20
links := oIE.document.parentWindow.frames[6].document.links
Loop % links.length  {
   link := links[A_Index - 1]
   MsgBox, % &quot;Link text: &quot; . link.innerText . &quot;`nLink href: &quot; . link.href
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-01-25T22:31:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123384#p123384</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Получение элемента из <a href => из IE]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123381#p123381" />
			<content type="html"><![CDATA[<p>https://www.mmorpg.com/sweepstakes<br />Ссылки на игры, что находятся в классе &quot;contestopen&quot;. Справа от описания есть названия игр, что являются ссылками, ссылки на игры из класса &quot;contestopen&quot; и нужны.</p>]]></content>
			<author>
				<name><![CDATA[Alex_Lexon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32135</uri>
			</author>
			<updated>2018-01-25T20:57:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123381#p123381</id>
		</entry>
</feed>
