Sign in to follow this  
Followers 0
Piyush

regex solution needed...!!

4 posts in this topic

<a href="http://link.songs.pk/song1.php?songid=7995"> No Problem</a>

<a href="http://link.songs.pk/song1.php?songid=7996"> Shakira</a>

these are the example of the html written on a page....i need to extract the link and the text of the link..(for e.g. http://link.songs.pk/song1.php?songid=7995, No problem) with the help....regex....

i have tried a lot bt was not able to extract..please help Posted Image

thx.....


[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello Piyush,

I wrote a small example for you, however, this will grab anything that has similar link formats from source code you are reading from. I suggest finding a way to define it better or, in a step before this one, try to grab the block of code that you need to read this from. I included a way to convert the information into a 2D array, to give the rest of your script an easier way to obtain the information. However, it could have errors depending on the other links within the source. test, play, and see what you can come up with.

#include <Array.au3>
Local $source = '<a href="http://link.songs.pk/song1.php?songid=7995">No Problem</a>' & @CRLF _
            & '<a href="http://link.songs.pk/song1.php?songid=7996">Shakira</a>'

Local $sre = StringRegExp($source,'\<a href\=\"(.*?)\"\>(.*?)\<\/a\>',3) ;This will grab both the link and the text you need.

;Here I include a way to convert that information into a 2D array
;$new_Array[n][0] will contain the link
;$new_Array[n][1] will contain the text
$row = (UBound($sre))/2
Local $new_Array[$row][2]
$dim = 0
For $s = 0 To UBound($sre)-2 Step 2
    $new_Array[$dim][0] = $sre[$s]
    $new_Array[$dim][1] = $sre[$s + 1]
    $dim +=1
Next

_ArrayDisplay($new_Array)

Enjoy!

Realm

Edit: Fixed a typo in my code.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

hey! thx....:graduated:

My pleasure, I had the time :(


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

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  
Followers 0