码迷,mamicode.com
首页 > 编程语言 > 详细

python-spider 第一关

时间:2020-07-29 09:54:19      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:range   erer   pandas   info   timestamp   app   apple   mes   imp   


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 第一关

标签:range   erer   pandas   info   timestamp   app   apple   mes   imp   

原文地址:https://www.cnblogs.com/ruhai/p/13394609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!