python-spider 第一关
Posted 如海
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-spider 第一关相关的知识,希望对你有一定的参考价值。
import datetime
import time
import json
import hashlib
import base64
import requests
import pandas
import browsercookie
from collections import Counter
import pandas
l = []
def get_token():
a = ‘9622‘
dt = datetime.datetime.now()
timestamp = str(dt.timestamp()).split(‘.‘)[0]
base_code = base64.b64encode((a + timestamp).encode("utf-8"))
data = hashlib.md5(base_code)
return data.hexdigest(), timestamp
safe, timestamp = get_token()
headers = {
‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE‘,
‘Referer‘: ‘http://www.python-spider.com/challenge/1‘,
‘safe‘: safe,
‘timestamp‘: timestamp
}
cj = browsercookie.chrome()
c = Counter(‘a‘)
for i in range(1,86):
url = ‘http://www.python-spider.com/challenge/api/json?page=%s&count=14‘%str(i)
res = requests.get(url, headers=headers, cookies=cj)
try:
t = res.json()[‘infos‘]
l.append(t)
except Exception as e:
pass
p = []
for i in l:
for x in i:
data = x[‘message‘]
p.append({‘m‘:data})
df = pandas.DataFrame(p)
df[df.m.str.contains(‘招‘)]
以上是关于python-spider 第一关的主要内容,如果未能解决你的问题,请参考以下文章