Jump to content

Searching for links in a page


scheda

Recommended Posts

Hi,

 

So I'm having some trouble with regex... of course...

 

Here's what's happening.

 

I'm building a Google scraper. It goes out, does a search for forums register pages, and grabs the links to them all.

 

I have everything working, I just need the regex to grab the proper links.

 

In my head I see the script grabbing all links that have register.php inside the href area. This is what my regex looks like right now.

 

<a href="(*)register.php" class=l>

 

However, I get this error when it runs.

 

Warning: preg_match_all() [function.preg-match-all]: Compilation failed: nothing to repeat at offset 9 in C:\wamp\www\forumfinder.php on line 33

 

I'm guessing it has to do with the quotes I have in there.

 

Any thoughts on how to fix this?

 

Thank you in advance!

Link to comment
https://forums.phpfreaks.com/topic/208856-searching-for-links-in-a-page/
Share on other sites

A * represents 0 or more characters matching the character preceding the *, in your case however the preceding character is an non-escaped bracket which is part of a capture group, therefore the * has 'nothing to repeat'. I will assume you are trying to capture URL of all anchor tags that have a href ending with register.php. On a side note your pattern is assumably missing delimiters, the only reason it hasn't thrown an error is the fact that the character at the start and end of your pattern, just happen to be valid delimiters.

 

preg_match_all('<a href="(.*?)register.php" class=l>',$html,$links);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

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.