Archive for the 'Tech' Category

使用python的lxml库解析html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import urllib2
import lxml.html as H

def getjarinfo(url):
    c=urllib2.urlopen(url)
   
    f=c.read()
    doc = H.document_fromstring(f)
    tables=doc.xpath("//table[@id='download']")    
    pinpais=doc.xpath("//td[@id='music']")
    jixings=doc.xpath("//div[@id='game']")
    jars = doc.xpath("//table[@id='download']//tr[2]/td[1]/a[1]")
    for j in range(len(pinpais)):
      print jars[j].get('href')
      print pinpais[j].text_content()        
      print jixings[j].text_content()
    e=doc.xpath(u"//div[text()='%s']" % u"游戏")
    describe=e[0].getnext().text_content()
    #r = doc.xpath("//table[@id='download']//tr[2]/td[1]/a[1]")[0]
    #jarurl=r.get('href')
   
if __name__ == '__main__':
    url='http://google.com/'
    getjarinfo(url)

怎样在linux下修改ID3信息

mid3iconv
由于Ubuntu中的Amarok等播放器只支持UTF8字符,所以在Amarok中常常出现乱码。解决方案如下:

1
sudo apt-get install python-mutagen

修改mp3中编码:
到你的music目录去

1
find . -iname "*.mp" -execdir mid3iconv -e GBK {} \;

6个Linux性能监控命令行工具

  1. htop http://htop.sourceforge.net/
    一个可以让用户与之交互的进程查看器。作为文本模式的应用程序,主要用于控制台或 X 终端中。当前具有按树状方式来查看进程,支持颜色主题,可以定制等特性。
  2. Continue reading ’6个Linux性能监控命令行工具’

Error: Could not stat() command file ‘/var/lib/nagios2/rw/nagios.cmd’

Error: Could not stat() command file ‘/var/lib/nagios2/rw/nagios.cmd’!

1
2
3
4
stop nagios2
/etc/nagios2# dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios2/rw
/etc/nagios2# dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios2
start nagios2

Linux For Thinkpad 下投影仪使用

安装完Linux一般都会发现快捷键不好用了。

1、简单方法
切入到文本控制台CTRL+ALT+F1
执行 echo crt_enable > /proc/acpi/ibm/video
切回图形界面就可以使用投影仪了。
注:执行前确认  /proc/acpi/ibm/video 存在
如果不存在请往下看。

2、复杂且有效方法

linux-wiki

http://www.thinkwiki.org/wiki/Problem_with_video_output_switching

平台还是流量?

Facebook是个平台,Twitter也是。其实应该是先有平台还是先有流量的问题。对于创业者来说这是个问题。我想成功的创业者,是应该考虑平台而不适流量。

但是对于只考虑流量的网站是否注定就说是失败的?那些众多的小站不是只考虑流量的内容网站吗?我想可能是因为内容站比平台站好做而已。对于创业者来说就是要不断模拟网站的变化做出提前的预期满足用户需求,以用户为中心,才是成功之道。市场调查、确定方向、分析用户群、分析潜在用户群、搭建平台、组织内容、服务用户。是否这才是正确之道?

在windows中设置Memcached服务启动参数

memcached

于是就想到直接修改windows服务的启动参数,操作如下,打开注册表,找到:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server 其中的ImagePath项的值为: c:\memcached\memcached.exe" -d runservice

改成:c:\memcached\memcached.exe" -p 12345 -m 128 -d runservice

ping 0xc0a8010a

ping network tool on windows

[fred@home ~]$ ping 0xc0a8010a
PING 0xc0a8010a (192.168.1.10) 56(84) bytes of data.
^C
--- 0xc0a8010a ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2479ms

Use fdisk fix hard disk error

Just did a sudo fdisk -l of my newly installed OS. I had manually configured the partitions with the Live CD install to allow for my /home to be on it’s own partition. The included screenshot of same indicates that my Partition table entries are not in disk order. Is this something I should correct? Can I expect problems with the partitioning as it is? If so, what should I do?

It is not a problem. You can “reset” them to the correct order but you would need to check your grub menu and fstab in case there were any references to “sdXX” instead of to UUIDs. The reason is at least two of the partition “sdXX” designations would change after you ‘reset’ them.

For those wishing to do so, here is the procedure. Note that your system will operate fine without making this change and you run the risk of screwing up your boot process or partition mounting if the partition designations no longer match in fstab or menu.lst:

sudo fdisk /dev/sda

at the prompt:
(for help)
at the prompt:

(extra functionality – experts only)
(fix)
(write to disk and exit)
You may get a warning that devices are in use and the new table will be used at the next boot.
Check fstab and menu.lst before rebooting.
Repeat for other drives.

SSH Tunnel扫盲

前些天,由于我不知道如何在Putty里拷贝字符而被朋友们取笑,着实糗了一把。不过被别人B4的一大好处就是你会知耻而后勇,这阵子通过研读PuTTY 中文教程,估计以后不会再犯同样的错误了,在学习Putty的同时偶然发现自己对SSH Tunnel的了解很匮乏,所以便有了今天这篇笔记。

SSH Tunnel有三种,分别是本地Local(ssh -NfL),远程Remote(ssh -NfR),动态Dynamic(ssh -NfD)。(含义参考man ssh

说明:在我们举例说明用法之前,先假设你有一台机器,它的IP是a.b.c.d。
Continue reading ‘SSH Tunnel扫盲’