+ Reply to Thread
Results 1 to 21 of 21

Extract links by href from text file

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Extract links by href from text file

    Hello everyone
    I have a text file which has html source for a web page and I need to extract the links according to specific pattern using regex
    The pattern would be at the start point
    Please Login or Register  to view this content.
    and would be at the end point like that
    Please Login or Register  to view this content.
    So I need to extract the link from the start point in https and ends with ?dl=0
    Example of valid link from the text file
    Please Login or Register  to view this content.
    Thanks advanced for help
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: Extract links by href from text file

    Here:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    Thanks a lot for your solution
    I need to extract all the links not only one. How can I achieve that?
    Please Login or Register  to view this content.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Extract links by href from text file

    Here is a UDF that will do that work.
    Please Login or Register  to view this content.
    Extract4Yasser VBA UDF.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    Thank you very much Mr. Marvin
    It works great. Now how can I extract all the instances not just the first instance?

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    Any help in this topic please?
    How can I extract all the links in the text file

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    Can it be done using regular expressions?

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    I expected that this issue can be solved using regular expressions !!
    It seems that I have to re-think of another workaround

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Extract links by href from text file

    Perhaps this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Extract links by href from text file

    I'd use this to keep it a bit cleaner to read.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    That's awesome
    Now this UDF grabs all links
    I need only the links that starts with ("href": "https) and ends with (?dl=0", "file_id")

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Extract links by href from text file

    My guess would be that the final output will not be a message box as I can't see the use, so I wasn't overly concerned about the formatting!

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    I would like the output to put each link in separate cell in column B

  14. #14
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Extract links by href from text file

    Try changing the pattern like this
    Please Login or Register  to view this content.

  15. #15
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Extract links by href from text file

    Revision to output to column B
    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    Thank you very very much xlnitwit for this awesome and brilliant solution. That's exactly what I was searching for
    Best and kind regards

  17. #17
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Extract links by href from text file

    You're welcome. Thank you, and bakerman, for the rep!

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    How to change the pattern to include this part too in the links
    Please Login or Register  to view this content.

  19. #19
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    I changed that line

    Please Login or Register  to view this content.
    But I need to know how to change the pattern itself

  20. #20
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Extract links by href from text file

    Just move the bracket to include it
    Please Login or Register  to view this content.

  21. #21
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Extract links by href from text file

    You are awesome. Thanks a lot for great help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extract specific columns from text file and export to another text file
    By KingTamo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-02-2017, 01:00 AM
  2. Extract URL inside a <a href> tag from a webpage
    By dylanrose in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2017, 07:48 AM
  3. Formula to Extract URL & Text from Href Tag
    By newbieexceldude in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 12-17-2016, 10:02 PM
  4. How to loop different href links after using winhttp.winhttprequest.5.1
    By lubbamkt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-25-2014, 08:40 AM
  5. [SOLVED] Get href links from a website
    By Sean Thomas in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-30-2013, 05:59 PM
  6. How to extract Information from an Excel File and entering those data in a text file?
    By bikash.nitk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2012, 12:13 PM
  7. Extract all these url links from this excel file?
    By jhess56 in forum Excel General
    Replies: 0
    Last Post: 07-25-2011, 08:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1