<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Scraping 101: Extracting Anchor Text with Regexp</title>
	<atom:link href="/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html/feed" rel="self" type="application/rss+xml" />
	<link>http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html</link>
	<description>Search Engines &#124; Blogs &#124; Marketting &#124; PHP/MYSQL &#124; CSS</description>
	<pubDate>Sun, 16 Jul 2017 15:40:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Don</title>
		<link>http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-27767</link>
		<dc:creator>Don</dc:creator>
		<pubDate>Mon, 15 Sep 2008 14:10:04 +0000</pubDate>
		<guid isPermaLink="false">http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-27767</guid>
		<description>The TreeBuilder library is actually pretty mature code and was made assuming that the HTML code is bad, so it works quite nicely, would handle stuff like nested anchors fine and doesn't break over such things as missing closing tags. Perl coders are usually really good at parsing since that's the languages strongest feature.  I doubt it is perfect, but it seems to handle most HTML docs ok. I just got a Y! API key and looped through the 1000 results and pulled anchor/image alt text tags along with their attributes off all the sites.</description>
		<content:encoded><![CDATA[<p>The TreeBuilder library is actually pretty mature code and was made assuming that the HTML code is bad, so it works quite nicely, would handle stuff like nested anchors fine and doesn&#8217;t break over such things as missing closing tags. Perl coders are usually really good at parsing since that&#8217;s the languages strongest feature.  I doubt it is perfect, but it seems to handle most HTML docs ok. I just got a Y! API key and looped through the 1000 results and pulled anchor/image alt text tags along with their attributes off all the sites.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Halfdeck</title>
		<link>http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-27766</link>
		<dc:creator>Halfdeck</dc:creator>
		<pubDate>Mon, 15 Sep 2008 10:45:43 +0000</pubDate>
		<guid isPermaLink="false">http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-27766</guid>
		<description>Interesting Don. One issue I see with your code though is it probably relies on valid HTML code to work. Also if you have stuff nested inside a href, anchor may not get parsed correctly. But thanks for posting the code. Though I implement scrapers in Java if I have some free time I'll definitely check it out.</description>
		<content:encoded><![CDATA[<p>Interesting Don. One issue I see with your code though is it probably relies on valid HTML code to work. Also if you have stuff nested inside a href, anchor may not get parsed correctly. But thanks for posting the code. Though I implement scrapers in Java if I have some free time I&#8217;ll definitely check it out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Don</title>
		<link>http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-27765</link>
		<dc:creator>Don</dc:creator>
		<pubDate>Fri, 12 Sep 2008 19:30:32 +0000</pubDate>
		<guid isPermaLink="false">http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-27765</guid>
		<description>Perl has some nice modules available for connecting to and parsing HTML documents. If you like regexp and haven't learned perl yet you should definitely check it out. It has built-in regexp support to make parsing stuff like HTML docs quick.  Here's some basic code that extracts nofollow links and their corresponding anchor text or alt text if its an image. note the code is messy :)

 use HTML::TreeBuilder;
use LWP::UserAgent;
use HTTP::Headers;
use URI::Escape;
use HTML::Parser;



$ua = LWP::UserAgent-&#62;new;
$ua-&#62;agent("Mozilla/5.0");
$ua-&#62;timeout(3000000);

$req = HTTP::Request-&#62;new(GET =&#62; "http://url.com");
$res = $ua-&#62;request($req);

if ($res-&#62;is_success) {
$tree = HTML::TreeBuilder-&#62;new_from_content($res-&#62;content);
if(defined $tree-&#62;look_down( '_tag' =&#62; 'a')){


@getlinks=$tree-&#62;look_down( '_tag' =&#62; 'a');

for($b=0;$battr('href')){
if($getlinks[$b]-&#62;attr('rel') &#38;&#38; $getlinks[$b]-&#62;attr('rel')=~/nofollow/gi ){
  print "Nofollow-&#62; " . $getlinks[$b]-&#62;attr('href') . "\n";

  if ($getlinks[$b]-&#62;as_text) {
   print "This is a text link\n";
   print "Anchor text-&#62; " . $getlinks[$b]-&#62;as_text . "\n";
  }

  $image = $getlinks[$b]-&#62;look_down( '_tag' =&#62; 'img');
 if ($image &#38;&#38; $image-&#62;attr('alt')) {
  print "This is a image link\n";
  print "Alt text-&#62; " . $image-&#62;attr('alt') . "\n";

}
}
}
}
 }
}</description>
		<content:encoded><![CDATA[<p>Perl has some nice modules available for connecting to and parsing HTML documents. If you like regexp and haven&#8217;t learned perl yet you should definitely check it out. It has built-in regexp support to make parsing stuff like HTML docs quick.  Here&#8217;s some basic code that extracts nofollow links and their corresponding anchor text or alt text if its an image. note the code is messy :)</p>
<p> use HTML::TreeBuilder;<br />
use LWP::UserAgent;<br />
use HTTP::Headers;<br />
use URI::Escape;<br />
use HTML::Parser;</p>
<p>$ua = LWP::UserAgent-&gt;new;<br />
$ua-&gt;agent(&#8221;Mozilla/5.0&#8243;);<br />
$ua-&gt;timeout(3000000);</p>
<p>$req = HTTP::Request-&gt;new(GET =&gt; &#8220;http://url.com&#8221;);<br />
$res = $ua-&gt;request($req);</p>
<p>if ($res-&gt;is_success) {<br />
$tree = HTML::TreeBuilder-&gt;new_from_content($res-&gt;content);<br />
if(defined $tree-&gt;look_down( &#8216;_tag&#8217; =&gt; &#8216;a&#8217;)){</p>
<p>@getlinks=$tree-&gt;look_down( &#8216;_tag&#8217; =&gt; &#8216;a&#8217;);</p>
<p>for($b=0;$battr(&#8217;href&#8217;)){<br />
if($getlinks[$b]-&gt;attr(&#8217;rel&#8217;) &amp;&amp; $getlinks[$b]-&gt;attr(&#8217;rel&#8217;)=~/nofollow/gi ){<br />
  print &#8220;Nofollow-&gt; &#8221; . $getlinks[$b]-&gt;attr(&#8217;href&#8217;) . &#8220;\n&#8221;;</p>
<p>  if ($getlinks[$b]-&gt;as_text) {<br />
   print &#8220;This is a text link\n&#8221;;<br />
   print &#8220;Anchor text-&gt; &#8221; . $getlinks[$b]-&gt;as_text . &#8220;\n&#8221;;<br />
  }</p>
<p>  $image = $getlinks[$b]-&gt;look_down( &#8216;_tag&#8217; =&gt; &#8216;img&#8217;);<br />
 if ($image &amp;&amp; $image-&gt;attr(&#8217;alt&#8217;)) {<br />
  print &#8220;This is a image link\n&#8221;;<br />
  print &#8220;Alt text-&gt; &#8221; . $image-&gt;attr(&#8217;alt&#8217;) . &#8220;\n&#8221;;</p>
<p>}<br />
}<br />
}<br />
}<br />
 }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SEO Company Reading - Hobo SEO UK</title>
		<link>http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-21361</link>
		<dc:creator>SEO Company Reading - Hobo SEO UK</dc:creator>
		<pubDate>Wed, 13 Feb 2008 03:08:30 +0000</pubDate>
		<guid isPermaLink="false">http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-21361</guid>
		<description>[...] Scraping 101: Extracting Anchor Text with Regexp, Half&#8217;s SEO Notebook [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Scraping 101: Extracting Anchor Text with Regexp, Half&#8217;s SEO Notebook [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Halfdeck</title>
		<link>http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-21347</link>
		<dc:creator>Halfdeck</dc:creator>
		<pubDate>Mon, 11 Feb 2008 23:25:38 +0000</pubDate>
		<guid isPermaLink="false">http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-21347</guid>
		<description>"how do you propose we capture all those HTML pages to see who is linking to whom with what anchor text?"

1. Using Yahoo API, pull backlinks to the home page only.
2. Pull sitewide backlinks.
3. Run a site: command, and pull the first 1,000 URLs.
4. For each URL, pull backlicks to that URL.
5. Hamlet Batista also suggested using keywords to pull even more backlinks.
7. Rerun, filtering out multiple urls from the same domain. (not filtering that is useful for finding sites that link sitewide; filtering it is useful for discovering a greater number of domains).

Obviously, even with all those API runs, this method will only dig up a subset of a site's backlinks, and you'd have to dig through the result set to weed out noise (links from myspace search pages, nofollowed blog comment links, links from scraper sites, etc).

If a single page links multiple times to a domain with different anchor text, that also brings up a problem most tools out there don't deal with.</description>
		<content:encoded><![CDATA[<p>&#8220;how do you propose we capture all those HTML pages to see who is linking to whom with what anchor text?&#8221;</p>
<p>1. Using Yahoo API, pull backlinks to the home page only.<br />
2. Pull sitewide backlinks.<br />
3. Run a site: command, and pull the first 1,000 URLs.<br />
4. For each URL, pull backlicks to that URL.<br />
5. Hamlet Batista also suggested using keywords to pull even more backlinks.<br />
7. Rerun, filtering out multiple urls from the same domain. (not filtering that is useful for finding sites that link sitewide; filtering it is useful for discovering a greater number of domains).</p>
<p>Obviously, even with all those API runs, this method will only dig up a subset of a site&#8217;s backlinks, and you&#8217;d have to dig through the result set to weed out noise (links from myspace search pages, nofollowed blog comment links, links from scraper sites, etc).</p>
<p>If a single page links multiple times to a domain with different anchor text, that also brings up a problem most tools out there don&#8217;t deal with.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Martinez</title>
		<link>http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-21345</link>
		<dc:creator>Michael Martinez</dc:creator>
		<pubDate>Mon, 11 Feb 2008 21:18:15 +0000</pubDate>
		<guid isPermaLink="false">http://seo4fun.com/blog/2008/02/08/scraping-101-extracting-anchor-text-with-regexp.html#comment-21345</guid>
		<description>Interesting post but how do you propose we capture all those HTML pages to see who is linking to whom with what anchor text?</description>
		<content:encoded><![CDATA[<p>Interesting post but how do you propose we capture all those HTML pages to see who is linking to whom with what anchor text?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
