pyQuery在python中,实现css选择器功能

# -*- coding=utf-8 -*-
import sys
import pdb
from pyquery import PyQuery as pyq
import urllib

url=r'http://list.taobao.com/browse/cat-0.htm'
u=urllib.urlopen(url)
buffer=u.read().decode('gbk')

doc=pyq(buffer)

cts=doc('.market-cat')
print sys.getfilesystemencoding()
#pdb.set_trace()
for i in cts:
    aa = pyq(i).find('h4').text()
    print '====',pyq(i).find('h4').text() ,'===='
    for j in pyq(i).find('.sub'):
        print pyq(j).text(),
    print '\n'

你可能感兴趣的:(python,python,css,buffer,import,url)