2015年10月23日 星期五

Alexa - a web page to show how pofitable of a web page

Alexa - http://www.alexa.com/ In internet point of view, browsing count means profit. This page can show the ranking of amount of access of a page. That is for simply, how profitable for the page is and the efficiency of putting advertisement there.

2015年10月2日 星期五

How To Download content in Python using urllib2 with example

I am working on a project that needs to download content from web and parse it's data in Python. I have done some modules which is useful in downloading stuff. Or I just share the source code.

= = =
#!/usr/bin/python2
import time
import urllib2

__user_agent = "Mozilla/5.0 (Windows NT 5.1; rv:40.0) Gecko/20100101 Firefox/40.0"

def url_req(url, cookie=None, max_retry=3, retry_wait_s=5):
    r_html = None
    retry = 0

    while 1 :
        if (retry == max_retry):
            break

        data_req = urllib2.Request(url)

        #cookie support
        data_req.add_header('User-Agent', __user_agent)
        if cookie is not None:
            data_req.add_header('Cookie', cookie)

        try:
            data_handler = urllib2.urlopen(data_req)
        except urllib2.URLError as e:
            print (e.reason)
            time.sleep(retry_wait_s)
            retry = retry+1
            continue
        except:
            pass
            time.sleep(retry_wait_s)
            retry = retry+1
            continue

        try: r_html = data_handler.read()
        except urllib2.URLError as e:
            print (e.reason)
            time.sleep(retry_wait_s)
            retry = retry+1



            r_html = None
            continue
        break

    return r_html

2015年10月1日 星期四

How To Create Windows Bootable USB on Linux

You know when working on Linux, there is still some constraint that is not easy to overcome. This time I would like to upgrade BIOS for my old Thinkpad. It seems the best choice with less risk is installing a Windows on another harddrive and upgrade it. But my laptop do not come with a DVD-ROM and also I don't have any external one. So I go for USB solution.

For all Linux bootable iso can be made through command "dd" but it doesn't work for Windows Disc as the MBR is different. So what I do is make use of a tools called "ms-sys"

Software Tools needed
Windows ISO (You should know how to get it)
gparted (partition the usb)
ms-sys

Steps:
1. use gparted to clear all partition on usb drive
2. use gparted to create NTFS partition on USB, set the partition as bootable
3. mount Windows ISO, copy all files from mount point to USB. "sync"
4. Call the magic "sudo ms-sys -7 /dev/sdX" to write the MBR to USB. I used Windows 7 as the example or you may read the help of ms-sys
5. unmount everything
6. Nice and Done and you got a bootable USB

Go Go Flash Bios!!