# coding:utf-8
import requests
from pyquery import PyQuery
from random_useragent import UserAgent # pip install r-useragent
headers = {
"User-Agent": UserAgent().android(),
}
def test(content):
try:
req = PyQuery(url=content, headers=headers,verify=False) # 和requests方法一样
title = req('title').text() or req('').text()
keywords = req('[name=keywords]').attr('content') or req('[name=Keywords]').attr('content')
description = req('[name=description]').attr('content') or req('[name=Description]').attr('content')
except Exception as e:
print('页面分析出现错误,错误内容:{}'.format(e))
return False, False, False
return title, keywords, description
# r = requests.get('https://zhihu.com', verify=False)
# print(test(r))
print(test(content='https://www.9ku.com'))