Jump to content
Sign in to follow this  
edgariyu

Get a part of a HTML

Recommended Posts

edgariyu

Hi everyone!!

I'm working on a script for get the links of a Google page. I tried two differents ways but nothing has worked. This is the first one:

$URL="http://www.google.es/search?q=comida+china&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:es-ES:official&client=firefox-a"

$WinHttpReq = ObjCreate("winhttp.winhttprequest.5.1") ;Realizamos la peticion HTTP

$WinHttpReq.open("GET",$URL)

$WinHttpReq.send()

$HTML = $WinHttpReq.ResponseText ;Recuperamos el HTML de la web

$array = _StringBetween($HTML, '<span class="f">','</span>')

Is the URL direcction correct? Because _StringBetween return me a 0 that means that there is an error with the request, and i don't know why :s

I tried too that way:

$oIE = _IECreate($URL)

and trying to get the links with _IELinkGetCollection, but i just want the links of the central panel, and are between <span class="f"></span> or at least is what firebug says :s

The paint is that i only want the links that are in the central column, not the adds of the right part. And in the same topic, how can i check if there is a page in a HTML? With StringRegExp??

Thanks for your help!!!

Share this post


Link to post
Share on other sites
DaleHohm

Use the DOM hierarchy something like this:

#include <IE.au3>

$oIE = _IECreate("http://www.google.es/search?q=comida+china&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:es-ES:official&client=firefox-a")
$oMiddle = _IEGetObjById($oIE, "ires") ; div id=ires
$oH3s = _IETagNameGetCollection($oMiddle, "h3") ; h3 tags contain the links you want
For $oH3 in $oH3s
    $oA = _IETagnameGetCollection($oH3, "a", 0) ; get reference to the link
    ConsoleWrite($oA.href & @CRLF) ; show link href
Next

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
edgariyu

Thanks for your quick answer DaleHohm!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.