Python大批量查寻重要词是不是是指数值词

2021-03-11 16:07 admin

Python大批量查寻重要词是不是是指数值词


短视頻,自新闻媒体,达人种草1站服务

简易的查寻1个重要词是不是为指数值词,暂不可以查寻指数值,过段時间科学研究下

# -*- coding: utf⑻ -*-

import urllib2

import urllib

import cookielib

import re

import bs4

URL_BAIDU_INDEX = u'';

# 还可以用这个

URL_BAIDU_TOKEN = '';

URL_BAIDU_LOGIN = '';

#设定客户名、登陆密码

username = '';

password = '';

#设定cookie,这里cookiejar可全自动管理方法,不用手动式特定

cj = cookielib.CookieJar();

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj));

urllib2.install_opener(opener);

reqReturn = urllib2.urlopen(URL_BAIDU_INDEX);

#获得token,

tokenReturn = urllib2.urlopen(URL_BAIDU_TOKEN);

matchVal = re.search(u'"token" : "(?P.*?)"',tokenReturn.read());

tokenVal = matchVal.group('tokenVal');

#结构登陆恳求主要参数,该恳求数据信息是根据抓包软件得到,对应恳求

postData = {

'username' : username,

'password' : password,

'u' : '',

'tpl' : 'pp',

'token' : tokenVal,

'staticpage' : '',

'isPhone' : 'false',

'charset' : 'UTF⑻',

'callback' : 'parent.bd__pcbs__ra48vi'

};

postData = urllib.urlencode(postData);

#推送登陆恳求

loginRequest = urllib2.Request(URL_BAIDU_LOGIN,postData);

loginRequest.add_header('Aept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');

loginRequest.add_header('Aept-Encoding','gzip,deflate,sdch');

loginRequest.add_header('Aept-Language','zh-CN,zh;q=0.8');

loginRequest.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36');

loginRequest.add_header('Content-Type','application/x--form-urlencoded');

sendPost = urllib2.urlopen(loginRequest);

#获得指数值网页页面

keylist = open('key.txt','r') #查寻重要词的文档

i = '如要查询有关数据信息'

for key in keylist:

key = key.strip('\n')

teibaUrl = '{0}'.format(key)

content = urllib2.urlopen(teibaUrl).read();

content = content.decode('gbk').encode('utf8');

if i in content:

print key,'并不是指数值重要词'

else:

print key,'指数值重要词'

喜爱python,SEO的同学能够加QQ群0