第一个小程序

#! /usr/bin/python
#-*- couding=utf-8  -*-
import requests
import urllib,urllib.request,urllib.parse
from bs4 import BeautifulSoup

#定义常量
UA = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.13 Safari/537.36"

#http://XXX/xxx?p=1a908806
#生成URL
u = input('\t请输入短链接\n\t如:R6mfOj0:')
u = ('http://t.cn/'+u)
print('\t输入的链接为'+u)


#获取短链接跳转地址
u = urllib.request.urlopen(u).geturl()
print('\n\n\n\t'+u)

#测试数量
x = int(input('\t测试数量:'))


#转换十进制
nux = (u[-8:])
numb= int(nux,16)
print("十进制"+nux)

#加入自身到列表
li = [numb]
print(li)
#生成数量
for i in range(1,x):


#列表
    li.append(int(numb)-int(i*100))

    li.append(int(numb)+int(i*100))


#hex1
    pid = ("%x" % li[(i)])
    print("PID"+pid)

#完整URL
    url = (u[:-8]+pid)

    print(url)



#header
    header={
        'Host':'xxxx.xxx.com',
        'Referee': url,
        'User-Agent':UA,
    }


#   获取参数
    v2ex_session = requests.Session()
    f = v2ex_session.get(url, headers=header)
    soup = BeautifulSoup(f.content, "html.parser")
    once = soup.find('input', {'id': 'p'})['value']
    print(once)


#   Data
    postData = {'score': '5',
                'p': pid
                }


#   POST 目标URL
    v2ex_session.post(url='http://XXXX/xxx',
                      data=postData,
                      headers=header)

#   查看源码
    print(f.content.decode())

  数量的地方还有写小问题 下次修改

posted on 2017-04-08 20:41  蓝码骑士  阅读(130)  评论(0)    收藏  举报

导航