百度网盘获取私密分享的文件
百度网盘获取私密分享的文件
阿豪boy 发表于9个月前
百度网盘获取私密分享的文件
  • 发表于 9个月前
  • 阅读 49
  • 收藏 0
  • 点赞 0
  • 评论 0

移动开发云端新模式探索实践 >>>   

# coding=utf-8


from bs4 import BeautifulSoup
import urllib
import urllib2
import sys
import requests
import cookielib
import re

reload(sys)
sys.setdefaultencoding('utf8')

'''
登陆到需要验证码的网盘
需要使用cookie
'''

def get_file_title(file_url,file_code):
    # 创建cookie
    c = cookielib.LWPCookieJar()
    # 绑定到urllib2的处理
    cookie = urllib2.HTTPCookieProcessor(c)

    # 附带cookie提交
    openr = urllib2.build_opener(cookie)

    hdr = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
        'Accept-Language': 'zh-CN,zh;q=0.8',
        'Connection': 'keep-alive',
        'Referer': 'http://www.baidu.com',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36'
    }

    url = 'http://www.baidu.com'
    req = urllib2.Request(url, headers=hdr)
    html = openr.open(url).read()

    req = urllib2.Request(file_url, headers=hdr)
    link = openr.open(file_url)
    url = link.geturl()
    # 获取网址的shareid和uk
    #print url, type(url)

    pattern = re.compile('shareid=(.*?)&')
    shareid = re.findall(pattern, url)[0]
    pattern = re.compile('uk=(.*)')
    uk = re.findall(pattern, url)[0]
  #  print 'shareid=', shareid
  #  print 'uk=', uk

    data = {
        'pwd': file_code,
        'vcode': '',
        'vcode_str': ''
    }

    '''
    Request URL:http://pan.baidu.com/share/verify?shareid=%s&uk=%s&t=1504011858347&bdstoken=null&channel=chunlei&clienttype=0&web=1&app_id=250528&logid=MTUwNDAxMTg1ODM1MDAuNTQxNDY3MTIyNzY2MDYzMg==
    
    '''

    url = 'http://pan.baidu.com/share/verify?shareid=%s&uk=%s&t=1504011858347&bdstoken=null&channel=chunlei&clienttype=0&web=1&app_id=250528&logid=MTUwNDAxMTg1ODM1MDAuNTQxNDY3MTIyNzY2MDYzMg==' % (
    shareid, uk)
#    print url
    req = urllib2.Request(url, headers=hdr)
    data = urllib.urlencode(data)
    html = openr.open(req, data=data).read()

    with open('t.html', 'wb') as f:
        f.write(html)
    '''
    {"errno":-9,"err_msg":"","request_id":4817706520363686291}        //密码错误
    {"errno":-62,"request_id":206026661042873124}                        //要验证码了
    {"errno":0,"err_msg":"","request_id":4817740255807962253}        //密码正确
    '''

    req = urllib2.Request(link.geturl())
    html = openr.open(req).read()
    with open('t.html', 'wb') as f:
        f.write(html)

    soup = BeautifulSoup(html, 'html.parser')
    title = soup.select('title')[0]
    return title.get_text().split('|')[0]

'''
2017-08-24-Python模拟登录12306官网-强子.wmv_免费高速下载|百度网盘-分享无限制
file_url = 'http://pan.baidu.com/s/1dFGkrkd'
file_code = 'l8xm'


20170821词云_免费高速下载
file_url = 'http://pan.baidu.com/s/1nvsTlJ7'
file_code = 'aqw6'


'''
file_url = 'http://pan.baidu.com/s/1nvsTlJ7'
file_code = 'aqw6'

print get_file_title(file_url,file_code)
http://pan.baidu.com/share/init?shareid=850519643&uk=3334463819 <type 'str'>
shareid= 850519643
uk= 3334463819
http://pan.baidu.com/share/verify?shareid=850519643&uk=3334463819&t=1504011858347&bdstoken=null&channel=chunlei&clienttype=0&web=1&app_id=250528&logid=MTUwNDAxMTg1ODM1MDAuNTQxNDY3MTIyNzY2MDYzMg==
2017-08-24-Python模拟登录12306官网-强子.wmv_免费高速下载|百度网盘-分享无限制

 

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 20
博文 835
码字总数 609928
×
阿豪boy
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: