Sovereign Posted November 4, 2010 Share Posted November 4, 2010 Alright so heres a little background information on the script im making in case it helps everyone understand. I have a list of businesses I need to gather a yellowpages link for, compiled into a txt file. It can already read that txt file and input the business name and address into yellowpages and submit it. What would be the easiest way to go about clicking the search result link that matches my business information that I inputed? Here is an example link: http://www.yellowpages.com/2929-southwest-fwy-houston-tx-77098/greenway-inn?g=2929+Southwest+Fwy%2C+Houston%2C+TX+77098&q=greenway+inn I need it to click the correct link to the business page so that I can save its url. Keep in mind I have no way of knowing what the link text is going to be. The only variable I have saved that could be used to help identify the link is the Address. I would post the page source but its REALLY long and im not sure how to do it correctly. You can easily get it by going to that link above though. Link to comment Share on other sites More sharing options...
Sovereign Posted November 4, 2010 Author Share Posted November 4, 2010 Any tips on how to get started? Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 4, 2010 Share Posted November 4, 2010 Start out by trying all the example scripts in the help file under the _IE* functions. That will give you ideas. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Sovereign Posted November 5, 2010 Author Share Posted November 5, 2010 Start out by trying all the example scripts in the help file under the _IE* functions. That will give you ideas.I've been going over as many functions as I can to try and find one useful for my situation but I'm to inexperienced to know what I'm looking for exactly. I know close to nothing about how html is organized so I can't figure out what variables I'm trying to look for in the source. I also cant tell if the address text is in some way attached to the link so that I can check that text and then click the link if it matches. Link to comment Share on other sites More sharing options...
Sovereign Posted November 5, 2010 Author Share Posted November 5, 2010 Here is the chunk of code I need to mess with, how would I go about pulling out the address and the url? the whole "class, div, span, id" thing has me completely lost. I'm pretty sure this code is repeated around 10 times per page so I need a way to access each section of this code in its 10 different instances to check the address and url in each. </h3> <span class="listing-address adr"> <span class="street-address"> 2401 Brookhollow Plaza Dr, </span> <span class="city-state"><span class="locality">Arlington</span>, <span class="region">TX</span> <span class="postal-code">76006</span> </span> </span> <a href="/arlington-tx/mip/hawthorn-suites-arlington-dfw-south-5601644/map?lid=5601644" class="map-link" rel="nofollow"><span class='raquo'>»</span> Map</a> <span class="business-phone phone"> (817) 640-1188 </span> <span class="additional-phones"> </span> <div class="distance"> 0 miles </div> Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 5, 2010 Share Posted November 5, 2010 I've been going over as many functions as I can to try and find one useful for my situation but I'm to inexperienced to know what I'm looking for exactly. I know close to nothing about how html is organized so I can't figure out what variables I'm trying to look for in the source. I also cant tell if the address text is in some way attached to the link so that I can check that text and then click the link if it matches.What you want to do is not a beginner's problem. If you are not willing to learn the basics first you can't be helped.There is no one command that will magically do this. Start with the basic tutorials in the help file. When you have the AutoIt basics down, try the example scripts under the _IE* functions and see how they work. You'll learn something about the IE Document Object Model (DOM) in the process, and then you'll be ready to start working on this problem. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Sovereign Posted November 7, 2010 Author Share Posted November 7, 2010 Alright I hope I'm on the right track with this. Can you tell me if I'm getting close? My function works all the way up until: if $h.className = "business-name fn org" Then $clicktxt = $h.GetElementsByTagName("A") msgbox(0,'', $clicktxt.href) _IENavigate($oIE,$clicktxt.href) endif The if statement works I know that for sure. But it doesn't know what ".href" is. It acts like me looking for the <A> tag inside of the Tag <H3> is alright but I'm not sure if that's possible. I hope it is because its going to make this program a lot easier to write. HTML Source <H3 class="business-name fn org" sizcache="11955" sizset="0"> <A class="no-tracks url " href="http://www.yellowpages.com/arlington-tx/mip/hawthorn-suites-arlington-dfw-south-5601644?lid=5601644">Hawthorn Suites Arlington-Dfw South</A> </H3> My Code Func Yellowpages($pName,$pAddress) _IENavigate($oIE,"http://www.yellowpages.com/") $oForm = _IEFormGetObjByName ($oIE, "searchform-form") $Query1 = _IEFormElementGetObjByName ($oForm, "search-terms") _IEFormElementSetValue ($Query1, $pName) $Query2 = _IEFormElementGetObjByName ($oForm, "search-location") _IEFormElementSetValue ($Query2, $pAddress) _IEFormSubmit ($oForm) $hfind = $oIE.document.GetElementsByTagName("h3") For $h in $hfind if $h.className = "business-name fn org" Then $clicktxt = $h.GetElementsByTagName("A") msgbox(0,'', $clicktxt.href) _IENavigate($oIE,$clicktxt.href) endif Next EndFunc Link to comment Share on other sites More sharing options...
Sovereign Posted November 8, 2010 Author Share Posted November 8, 2010 Still having trouble getting this to work, any tips? Link to comment Share on other sites More sharing options...
DaleHohm Posted November 8, 2010 Share Posted November 8, 2010 (edited) GetElementsByTagName returns a collection, not a single object. $clicktxt.href is therefore invalid. If you used _IETagnameGetCollection you'd get the advantage of IE.au3's error handling. Also, change if $h.className = "business-name fn org" Then to if String($h.className) = "business-name fn org" Then because, if the element does not have a class, $h.className returns numeric 0, an interger comparison is performed with a sting (which evaluates to an integer 0) and returns True every time. Dale Edited November 8, 2010 by DaleHohm 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now