Showing posts with label software. Show all posts
Showing posts with label software. Show all posts

2009-06-18

How to write a Java-based HTML-Crawler?

It's actually a task from my test work. First idea that came to me is: Use an instance of XMLReader to fetch a page, then use regular expression to parse, save the results with the help of XMLWriter. Such a way seems naive, but almost non-usable! So let me explain the difficulty which can be confronted.


1. Internet is a mess.



There are too many web pages in the cyberspace that do NOT pay any attention to the web standard (X)HTML. So we can see a lot of nested tags, unpaired tags and even worse, badly programmed JavaScript may be in just one page.



2. Ads are confusing.


Now come Advertisements with different formats, e.g. Text, Flash, Images and Videos(!). Most of them live with a lot of JavaScript to improve their impact. Some use even non-standard tags such as <noscript> or browser-specific tags.


3. Ajax is not so user-friendly.

We all love to use Ajax technology. A typical Ajax use case is to let some texts loaded dynamically, then it results a severe problem with a HTML-Parser. If the parser saves the fetched HTML-page in a cache, the cache file contains a lot of JavaScript which load elements later. So with the cache file we cannot get what we want normally.


What can we do with all those?


The current popular solution is to use the HTML or Webpage validation tools! Between different libraries HTMLUnit will fit our requirement exactly. The project describes itself as a "GUI-Less browser for Java programs". So we can handle a webpage just like we see it in our browser. The above disadvantages could be then avoided.


Interesting is, HTMLUnit is originally a java unit testing framework for testing web based applications. It is similar in concept to HTTPUnit but is very different in implementation.


For beginners, HTMLUnit provides a very simple documentation to "Get Started". With the examples provided on the website it's okay to write a HTML-Crawler now.


2008-02-18

Strange problem with file copying in Windows Explorer

Since I sometimes need to use chinese in Windows, I set up my Windows XP under "Control Panel" -> "Regional and Language Options" -> "Advanced" -> "non-Unicode Program" Encoding -> "Simplified Chinese".

Now I get a big problem. I copied a zip file from a Linux box to my local computer. The copy process was ok and the zip file could be extracted too. Then I tried to copy that zip file to a directory on a machine with windows server 2003 enterprise version using Copy/Paste. The copy process seemed normal, but when I opened the file directly on the target machine and tried to extract it, WinRar told me "the zip file is corrupt!".

If I change the non-Unicode Program's Encoding to something like "German", then the problem will not happen. It seems that the windows explorer is a non-unicode program?!

My Windows is already updated to SP2. The IE version is still version 6.

Until now I haven't find any solution to this problem.

2008-01-31

Hide every application in the system tray!

Today I've tried a software called TrayIt! From its name you can see what it is for. ;-)

Yes, it's used normally to hide an application into the system tray.

Usage from the author's website:

TrayIt! runs on Windows 95/98/Me, NT/2000/XP/Vista and does NOT require any installation.

Simply create a new folder and place TrayIt!.exe and TrayIt!.dll there. When started, TrayIt! will show a dialog box with a short explanation how to use it. You may choose to load TrayIt! on system startup by selecting "Option" and checking "Load TrayIt! on StartUp" box.

  1. You can temporarily put any window in the system tray by keeping down the button when minimizing the window.

  2. To always keep window in the system tray when minimized, click with the RIGHT mouse button on the corresponding icon created in the tray in the previous step and check "Place in System Tray" in the popup menu.

  3. Clicking with the right mouse button on the minimize icon will bring TrayIt! context menu for this window. Just check "Place in System Tray" in the popup menu to make window always go to the tray.

  4. Please note that context menu will work only for the standard minimize icon and will not pop-up if the program use skins like MS Media player.


It's really useful because many programs don't provide the funtion of "minimize to the system tray". Currently I use it to hide the opera in my system tray and it works!

Download it!

2008-01-24

HOWTO: Set Up a CVS Repository Server under Linux

Since I want to use CVS as my project version control system, I decide to set up a CVS server on a Linux box.

I try to follow the instruction from [HOW-TO Install and Configure a CVS Repository Server] to get my work done, but there are so many problems happened.

First of all, the Linux is an old SuSE Linux distribution. CVS is already installed on the machine, which can be checked in the graphical config tool "yast" or "yast2".

Since I don't want to specify the passwords for every cvs user, it's better if the cvs server can use the users of the Linux sytem. It can be achieved by adding a line in the /config file.

Assumed that you create a repository in the directory /usr/local/cvsroot with the command:
cvs -d /usr/local/cvsroot init
then CVS will create a directory /CVSROOT under /usr/local/cvsroot. The config file of cvs is right in /usr/local/cvsroot/CVSROOT/. Open it and find a line like:

#SystemAuth=no
change it to

SystemAuth=yes
Then CVS knows you want to use the password of the users from the system.

I intend to use the machine as a CVS Repository Server, that means, the repository should be accessed remotely.

In order to do that, the cvs pserver should listen to the port 2041, which is enabled by inetd or xinetd. Since both are not existed in my system, I download the xinetd from its website.

After extract the downloaded source, you can use the command

tar -xvf xinetd-version.tar.gz
to extract the source codes.

Change your current path to ./xinetd-version, then just execute the following commands to install xinetd:

./configure
make
make install
cp xinetd/sample.conf /etc/xinetd.conf
cp xinetd/xinetd /etc/init.d/
Modify the file /etc/xinetd.conf so that it will run the cvspserver automatically:

service cvspserver
{
socket_type = stream
protocol = tcp
wait = no
user = root
passenv =
server = /usr/bin/cvs
server_args = --allow-root=/usr/local/cvsroot pserver -f
}

Now start xinetd with
/etc/init.d/xinetd
After such a long long process, the CVS server should be running on the machine now. You can verify it by:

cvs -d :pserver:username@localhost:/usr/local/cvsroot login

I must say, it's somehow frustrated to set up such a CVS server if you find there are so much difficult on your way. :(

2008-01-17

Project management

There are a lot of softwares for project management. Microsoft Project is the most famous one of them. But what if you want to use such kind of softwares under Linux and Mac? VM? Not a good solution.

Now, if you like Open Source Software, OpenProj is a very good substitution. It has not only Windows version, but also Linux and Mac version.

So try it.

免费下载项目管理软件

2007-09-03

Best zip software on the earth!

There are many zip softwares on the earth. Maybe thousand? I don't know. After long time seeking my most favorate zip software, I've chosen 7-Zip!

The reason:
  1. It's open source, which means it's completely free.
  2. It supports most archive format, including 7z, ZIP, GZIP, BZIP2, TAR and RAR.
  3. it integrates into the windows explorer.
  4. It has 63 language support.

An interesting thing is, the english version of 7-Zip website doesn't provide the beautiful icon set that is available to chinese users.




So here it is:

for v4.2: http://www.7-zip.org/zh-cn/7z_iconset.exe
for v4.53: http://www.7-zip.org/zh-cn/7z-iconset-453.exe

Just download it according to your 7-Zip version and install it.

Enjoy it!