<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>acloudtree &#187; REGEX</title>
	<atom:link href="http://www.acloudtree.com/category/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acloudtree.com</link>
	<description>Programming, Computers, Writing, Economics, and Life</description>
	<lastBuildDate>Sat, 10 Jul 2010 02:00:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>(Nerd) Mechanize &amp; Javascript</title>
		<link>http://www.acloudtree.com/nerd-mechanize-javascript/</link>
		<comments>http://www.acloudtree.com/nerd-mechanize-javascript/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 17:02:04 +0000</pubDate>
		<dc:creator>jared.folkins</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[REGEX]]></category>
		<category><![CDATA[Scraping]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Mechanize]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.acloudtree.com/?p=101</guid>
		<description><![CDATA[This is from the mechanize site, wish I would have read it before I started.
Since Javascript is completely visible to the client, it cannot be used to prevent a scraper from following links. But it can make life difficult, and until someone writes a Javascript interpreter for Perl or a Mechanize clone to control Firefox, [...]]]></description>
			<content:encoded><![CDATA[<p>This is from the mechanize site, wish I would have read it before I started.</p>
<blockquote><p>Since Javascript is completely visible to the client, it cannot be used to prevent a scraper from following links. But it can make life difficult, and until someone writes a Javascript interpreter for Perl or a Mechanize clone to control Firefox, there will be no general solution. But if you want to scrape specific pages, then a solution is always possible.</p>
<p>One typical use of Javascript is to perform argument checking before posting to the server. The URL you want is probably just buried in the Javascript function. Do a regular expression match on $mech-&gt;content() to find the link that you want and $mech-&gt;get it directly (this assumes that you know what you are looking for in advance).</p>
<p>In more difficult cases, the Javascript is used for URL mangling to satisfy the needs of some middleware. In this case you need to figure out what the Javascript is doing (why are these URLs always really long?). There is probably some function with one or more arguments which calculates the new URL. Step one: using your favorite browser, get the before and after URLs and save them to files. Edit each file, converting the the argument separators (&#8216;?&#8217;, &#8216;&amp;&#8217; or &#8216;;&#8217;) into newlines. Now it is easy to use diff or comm to find out what Javascript did to the URL. Step 2 &#8211; find the function call which created the URL &#8211; you will need to parse and interpret its argument list. Using the Javascript Debugger Extension for Firefox may help with the analysis. At this point, it is fairly trivial to write your own function which emulates the Javascript for the pages you want to process.</p>
<p>Here&#8217;s annother approach that answers the question, &#8220;It works in Firefox, but why not Mech?&#8221; Everything the web server knows about the client is present in the HTTP request. If two requests are identical, the results should be identical. So the real question is &#8220;What is different between the mech request and the Firefox request?&#8221;</p>
<p>The Firefox extension &#8220;Tamper Data&#8221; is an effective tool for examining the headers of the requests to the server. Compare that with what LWP is sending. Once the two are identical, the action of the server should be the same as well.</p>
<p>I say &#8220;should&#8221;, because this is an oversimplification &#8211; some values are naturally unique, e.g. a SessionID, but if a SessionID is present, that is probably sufficient, even though the value will be different between the LWP request and the Firefox request. The server could use the session to store information which is troublesome, but that&#8217;s not the first place to look (and highly unlikely to be relevant when you are requesting the login page of your site).</p>
<p>Generally the problem is to be found in missing or incorrect POSTDATA arguments, Cookies, User-Agents, Accepts, etc. If you are using mech, then redirects and cookies should not be a problem, but are listed here for completeness. If you are missing headers, $mech-&gt;add_header can be used to add the headers that you need.</p></blockquote>
<p><a title="Mechanize" href="http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize/FAQ.pod#I_have_this_web_page_that_has_JavaScript_on_it,_and_my_Mech_program_doesn%27t_work." target="_blank">LINK</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acloudtree.com/nerd-mechanize-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>bbbUM (BendBroadBand Usage Monitor)</title>
		<link>http://www.acloudtree.com/bbbum-bendbroadband-usage-monitor/</link>
		<comments>http://www.acloudtree.com/bbbum-bendbroadband-usage-monitor/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 01:36:54 +0000</pubDate>
		<dc:creator>jared.folkins</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[REGEX]]></category>
		<category><![CDATA[bend]]></category>
		<category><![CDATA[broadband]]></category>
		<category><![CDATA[capping]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[ISP]]></category>
		<category><![CDATA[oregon]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.acloudtree.com/?p=32</guid>
		<description><![CDATA[As of July 1st 2008, BendBroadBand (my ISP) now limits their customers monthly usage to 100GB. Should you go over this amount, they will charge you $1.50 per GB. In order to monitor this, BendBroadBand allows you to login to their website to track your usage. I was getting sick of logging in everyday, so [...]]]></description>
			<content:encoded><![CDATA[<p>As of July 1st 2008, BendBroadBand (my ISP) now limits their customers monthly usage to 100GB. Should you go over this amount, they will charge you $1.50 per GB. In order to monitor this, BendBroadBand allows you to login to their website to track your usage. I was getting sick of logging in everyday, so I decided to tackle the problem with some OOP (object oriented programming) using PHP5, PEAR::<em>Mail, </em>and some regular expressions. I ended up creating <strong>bbbUM</strong>, as in &#8220;Dude, I have to monitor my internet usage and I&#8217;m totally bbbUM&#8217;ed&#8221;. This sweet little program runs once a day as a cron job and sends a text message to my cell phone that contains my current usage.</p>
<p>The file that needs to be executed (should it not be obvious) is the <strong>bbbMail.php</strong>. For the sake of clarity, I have written the 3 variables that you will need to change in <strong>bold</strong>.</p>
<p><a href="http://acloudtree.com/wp-content/uploads/2008/07/bbbum.tar" title="bbbUM Version 1.0">bbbUM Version 1.0</a><br />
<code><br />
&lt;php<br />
&nbsp;<br />
//you need PEAR::Mail installed for this to work<br />
require_once('Mail.php');<br />
&nbsp;<br />
//path to the bbbClass.inc.php file<br />
require_once('bbbClass.inc.php');<br />
&nbsp;<br />
//create new bbb object<br />
$obj = new bbbUM;<br />
&nbsp;<br />
//email where you wish the message sent<br />
$obj-&gt;setEmail('<strong>5415551212@vtext.com</strong>');<br />
&nbsp;<br />
//bbb username/email<br />
$obj-&gt;setUserName('<strong>jdoe@bendbroadband.com</strong>');<br />
&nbsp;<br />
//password<br />
$obj-&gt;setPassword('<strong>123456</strong>');<br />
&nbsp;<br />
//method that sends mail<br />
$obj-&gt;bbbSend();<br />
&nbsp;<br />
?&gt;<br />
&nbsp;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acloudtree.com/bbbum-bendbroadband-usage-monitor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
