存档

文章标签 ‘pyquery’

pyquery:Python版的jQuery,HTML页面解析好工具

2017年9月20日 没有评论
# coding=utf-8

import requests
from pyquery import PyQuery as pq

#set request header
head_req = {
'User-Agent':'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
'Referer':'http://www.baidu.com/'
}

url = 'http://zhixing.bjtu.edu.cn/portal.php'
r = requests.get(url, headers=head_req)

#build pyquery object from response-content
page = pq(r.content)

#get page title
title = page.find('title')
print title.html()

#get page keyword
kw = page.find('meta[name="keywords"]')
print kw.attr('content')
分类: Python, 开发 标签: ,