Author Topic: Searching for links in a page  (Read 453 times)

0 Members and 1 Guest are viewing this topic.

Offline schedaTopic starter

  • Irregular
  • Posts: 20
    • View Profile
Searching for links in a page
« on: July 25, 2010, 03:12:25 PM »
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.

Code: [Select]
<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!

Offline Hybride

  • Enthusiast
  • Posts: 276
  • Morning Star
    • View Profile
    • Hybride Design
Re: Searching for links in a page
« Reply #1 on: July 25, 2010, 06:41:34 PM »
What is your entire preg_match statement? The error goes down to that the regex had nothing to match against.
Portfolio: Hybride Web Design
Latest: Time Series, Investment Advisors
web design by Immortal Design

Quote from: CABAL
Cybernetic intelligence will always be superior.

Offline schedaTopic starter

  • Irregular
  • Posts: 20
    • View Profile
Re: Searching for links in a page
« Reply #2 on: July 25, 2010, 08:13:26 PM »
Here it is.

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

Offline cags

  • Guru
  • Fanatic
  • *
  • Posts: 3,250
  • Gender: Male
    • View Profile
    • TiB Studios
Re: Searching for links in a page
« Reply #3 on: July 26, 2010, 04:13:25 AM »
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);

 
CodeCanyon - Cheap, High Quality, Ready Made Scripts.

Online sasa

  • Guru
  • Fanatic
  • *
  • Posts: 3,011
  • Gender: Male
    • View Profile
Re: Searching for links in a page
« Reply #4 on: July 29, 2010, 01:39:17 PM »
orpreg_match_all('<a href="[^"]*register.php" class=l>',$html,$links);