mac os安装pyquery

mac已经有python 2.7了,里面也已经有easy_install了

所以可以直接:sudo easy_install pyquery即可安装html的解析pyquery

使用:

#!/usr/bin/env python
# encoding: utf-8

from pyquery import PyQuery as pyq
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

class CrawlPython:
    def __init__(self, url):
        self.url = url

    def crawlW3C(self):
        doc = pyq(url=self.url)
        cts = doc('#leftcolumn a')
        pythonTXT = open("python.txt", "w")

        for data in cts:
            pythonTXT.write(pyq(data).text() + '\n') #写入到文件中
            print pyq(data).text()
            print '\n'

if __name__ == '__main__':
    crawl = CrawlPython('http://www.runoob.com/python/python-object.html')
    crawl.crawlW3C()




你可能感兴趣的:(python)