<!–
A Web-Harvest script that crawls through the pages of a Google Group forum
and saves the messages as an mbox file.
By: Nils Kaiser (blog.nils-kaiser.de)
This work is licensed under the Creative Commons Attribution 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/legalcode
Please mention my name and blog address as above if you reuse or distribute this work.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
–>
<config charset="UTF-8">
<!– *** EDIT: set Google Group forum to crawl (main page of a discussion
make sure that the params gvc=2 and hl=en are used –>
<var-def name="discussionMainUrl" overwrite="false">http://groups.google.com/group/youtube-api-gdata/topics?hl=en&gvc=2</var-def>
<!– *** EDIT: set output file name –>
<var-def name="outputFile" overwrite="false">c:/output/output.mbox</var-def>
<!–
function download-multipage-list, removed typos
adapted from http://web-harvest.sourceforge.net/samples.php?num=0
Copyright © 2006 by vnikic at users.sourceforge.net
–>
<function name="download-multipage-list">
<return>
<while condition="${pageUrl.toString().trim().length() > 0}" maxloops="${maxloops}" index="i">
<empty>
<var-def name="content">
<html-to-xml>
<http url="${pageUrl}"/>
</html-to-xml>
</var-def>
<var-def name="nextLinkUrl">
<xpath expression="${nextXPath}">
<var name="content"/>
</xpath>
</var-def>
<var-def name="pageUrl">
<case>
<if condition="${nextLinkUrl.toString().length() > 0}">
<template>${sys.fullUrl(pageUrl, nextLinkUrl.toString().trim())}</template>
</if>
</case>
</var-def>
</empty>
<xpath expression="${itemXPath}">
<var name="content"/>
</xpath>
</while>
</return>
</function>
<!– from line included, thunderbird does not care about receiver and
date is only used to check for new mail, i.e. useless here.
see http://www.qmail.org/man/man5/mbox.html –>
<var-def name="fromLine">From - Sat Jul 12 19:52:07 2008</var-def>
<!– clear output file as we use append later –>
<file action="write" type="text" path="${outputFile}"/>
<!– collects all thread urls –>
<var-def name="threadUrls">
<call name="download-multipage-list">
<call-param name="pageUrl"><var name="discussionMainUrl"/></call-param>
<call-param name="nextXPath">//div[@class='maincontbox']//a[contains(.,'Older')]/@href</call-param>
<call-param name="itemXPath">//div[@class='maincontoutboxatt']//a[contains(@href,'browse_thread')]/@href</call-param>
<call-param name="maxloops"></call-param>
</call>
</var-def>
<!– open each thread –>
<loop item="threadUrl" index="i" filter="unique">
<list>
<var name="threadUrls"/>
</list>
<body>
<empty>
<!– absolutize thread url –>
<var-def name="threadUrlFull">
<template>${sys.fullUrl(discussionMainUrl, threadUrl.toString().trim())}</template>
</var-def>
<!– collect all original messages urls –>
<var-def name="originalMsgUrls">
<call name="download-multipage-list">
<call-param name="pageUrl"><var name="threadUrlFull"/></call-param>
<call-param name="nextXPath">//div[@class='maincontbox']/table[1]//nobr[@id='thread_page_links_site']/a[contains(.,'Newer >')]/@href</call-param>
<call-param name="itemXPath">//div[@class='exh']//a[.='Show original']/@href</call-param>
<call-param name="maxloops"></call-param>
</call>
</var-def>
<!– loop through messages in thread (original view) –>
<loop item="originalMsgUrl" index="j" filter="unique">
<list>
<var name="originalMsgUrls"/>
</list>
<body>
<empty>
<!– get original message –>
<var-def name="originalMsgContent">
<http url="${sys.fullUrl(discussionMainUrl, originalMsgUrl.toString().trim() + "&output=gplain")}"/>
</var-def>
<!– need to quote lines starting with "From ",">
From ", ">>From ", ">>>From "…
see http://www.qmail.org/man/man5/mbox.html
–>
<var-def name="originalMsgContentQuoted">
<regexp replace="true">
<regexp-pattern>(?m)^([>]*From )</regexp-pattern>
<regexp-source>
<var name="originalMsgContent"/>
</regexp-source>
<regexp-result>
<template>>${_1}</template>
</regexp-result>
</regexp>
</var-def>
<!– process message content –>
<var-def name="originalMsgContentProcessed">
<template>${"" + fromLine + "\n" + originalMsgContentQuoted + "\n\n"}</template>
</var-def>
<!– append content of <pre>
to file –>
<file action="append" type="binary" path="${outputFile}">
<var name="originalMsgContentProcessed"/>
</file>
</empty>
</body>
</loop>
</empty>
</body>
</loop>
</config>