marcotv Posted February 18, 2010 Share Posted February 18, 2010 (edited) Hi guys, i'm a fan of autoit from many years! This is my problem. I have the source html code oh an html page For example this: <html> example text <a href="www.url1.com">description1</a> <a href="www.url2.com">description2</a> <a href="www.url3.com">description3</a> </html> I would like to get a bidimensional array (possibly without using ie browser) that contains all the links and their description: array={(www.url1.com,description1),(www.url2.com,description2),(www.url3.com,description3)} Which is the best solution? Thank you Edited February 18, 2010 by marcotv Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 18, 2010 Moderators Share Posted February 18, 2010 marcotv,Welcome to the the AutoIt forum. Not sure about the "best", but it certainly works:#include <Array.au3> #include <String.au3> $sSource = '<html>' & @CRLF & _ 'example text' & @CRLF & _ '<a href="www.url1.com">description1</a>' & @CRLF & _ '<a href="www.url2.com">description2</a>' & @CRLF & _ '<a href="www.url3.com">description3</a>' & @CRLF & _ '</html>' $aArray1 = _StringBetween($sSource, '<a href="', '">description') $aArray2 = _StringBetween($sSource, '.com">', '</a>') Global $a2DArray[UBound($aArray1)][2] For $i = 0 To UBound($aArray1) - 1 $a2DArray[$i][0] = $aArray1[$i] $a2DArray[$i][1] = $aArray2[$i] Next _ArrayDisplay($a2DArray)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
marcotv Posted February 18, 2010 Author Share Posted February 18, 2010 marcotv, Welcome to the the AutoIt forum. Not sure about the "best", but it certainly works: #include <Array.au3> #include <String.au3> $sSource = '<html>' & @CRLF & _ 'example text' & @CRLF & _ '<a href="www.url1.com">description1</a>' & @CRLF & _ '<a href="www.url2.com">description2</a>' & @CRLF & _ '<a href="www.url3.com">description3</a>' & @CRLF & _ '</html>' $aArray1 = _StringBetween($sSource, '<a href="', '">description') $aArray2 = _StringBetween($sSource, '.com">', '</a>') Global $a2DArray[UBound($aArray1)][2] For $i = 0 To UBound($aArray1) - 1 $a2DArray[$i][0] = $aArray1[$i] $a2DArray[$i][1] = $aArray2[$i] Next _ArrayDisplay($a2DArray) M23 thank you for the reply anyway the source code I indicated was only an example for example i can have this source code: <html> example text <a href="www.house.net">house</a> <a href="www.car.com">car</a> <a href="www.pc.biz">computer/a> <a href="animal.com">cat/a> </html> in this case, your solution doesn't function Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 18, 2010 Moderators Share Posted February 18, 2010 marcotv,You will have to adjust the _StringBetween parameters to match the actual file structure. For example, this works on the example you just posted: #include <Array.au3> #include <String.au3> $sSource = '<html>' & @CRLF & _ 'example text' & @CRLF & _ '<a href="www.house.net">house</a>' & @CRLF & _ '<a href="www.car.com">car</a>' & @CRLF & _ '<a href="www.pc.biz">computer/a>' & @CRLF & _ '<a href="animal.com">cat/a>' & @CRLF & _ '</html>' $aArray1 = _StringBetween($sSource, '<a href="', '">') _ArrayDisplay($aArray1) $aArray2 = _StringBetween($sSource, '">', '/') _ArrayDisplay($aArray2) Global $a2DArray[UBound($aArray1)][2] For $i = 0 To UBound($aArray1) - 1 $a2DArray[$i][0] = $aArray1[$i] If StringRight($aArray2[$i], 1) = "<" Then $aArray2[$i] = StringTrimRight($aArray2[$i], 1) $a2DArray[$i][1] = $aArray2[$i] Next _ArrayDisplay($a2DArray)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
marcotv Posted February 19, 2010 Author Share Posted February 19, 2010 (edited) marcotv, You will have to adjust the _StringBetween parameters to match the actual file structure. For example, this works on the example you just posted: #include <Array.au3> #include <String.au3> $sSource = '<html>' & @CRLF & _ 'example text' & @CRLF & _ '<a href="www.house.net">house</a>' & @CRLF & _ '<a href="www.car.com">car</a>' & @CRLF & _ '<a href="www.pc.biz">computer/a>' & @CRLF & _ '<a href="animal.com">cat/a>' & @CRLF & _ '</html>' $aArray1 = _StringBetween($sSource, '<a href="', '">') _ArrayDisplay($aArray1) $aArray2 = _StringBetween($sSource, '">', '/') _ArrayDisplay($aArray2) Global $a2DArray[UBound($aArray1)][2] For $i = 0 To UBound($aArray1) - 1 $a2DArray[$i][0] = $aArray1[$i] If StringRight($aArray2[$i], 1) = "<" Then $aArray2[$i] = StringTrimRight($aArray2[$i], 1) $a2DArray[$i][1] = $aArray2[$i] Next _ArrayDisplay($a2DArray) M23 thank you very much! great. I use it, it's very simple. Yesterday i was at work and I was in a hurry. autoit: great lenguage and great support Edited February 19, 2010 by marcotv 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