当前位置: 首页>>代码示例>>Python>>正文


Python urllib.Request方法代码示例

本文整理汇总了Python中urllib.Request方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.Request方法的具体用法?Python urllib.Request怎么用?Python urllib.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib的用法示例。


在下文中一共展示了urllib.Request方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hanlp_releases

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def hanlp_releases(cache=True):
    global HANLP_RELEASES
    if cache and HANLP_RELEASES:
        return HANLP_RELEASES
    # print('Request GitHub API')
    req = urllib.Request('http://nlp.hankcs.com/download.php?file=version')
    req.add_header('User-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36')
    if PY == 3:
        content = urllib.urlopen(req).read()
    else:
        content = urllib.urlopen(req).read()
    content = json.loads(content.decode())
    jar_version, jar_url, data_version, data_url = content
    meta = [(jar_version, jar_url, data_version, data_url)]
    HANLP_RELEASES = meta
    return meta 
开发者ID:hankcs,项目名称:pyhanlp,代码行数:18,代码来源:__init__.py

示例2: run_simulation

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def run_simulation(self):
        global TARGET, ADDR, VULN_VAR, TIMEOUT, REQ_TOTAL,\
            METHOD, OTHER_VARIABLES
        tmp = OTHER_VARIABLES
        tmp[VULN_VAR] = self.genome
        try:
            if METHOD == 0:
                prep = urllib.urlencode(tmp)
                r = urllib.urlopen('http://%s/%s' % (TARGET, ADDR), data=prep, timeout=TIMEOUT)
            else:
                prep = urllib.urlencode(tmp)
                req = urllib.Request('http://%s/%s' % (TARGET, ADDR), data=prep)
                r = urllib.urlopen(req)
            REQ_TOTAL += 1
            self.m_text['text'] = r.get_data()
            self.m_text['url'] = r.get_full_url()
            self.m_text['status_code'] = r.getcode()
        except:
            pass
        return self.m_text 
开发者ID:war-and-code,项目名称:jawfish,代码行数:22,代码来源:jf-web.py

示例3: deleteMember

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def deleteMember(ChatRoomName, UserNames):
    url = base_uri + '/webwxupdatechatroom?fun=delmember&pass_ticket=%s' % (pass_ticket)
    params = {
        'BaseRequest': BaseRequest,
        'ChatRoomName': ChatRoomName,
        'DelMemberList': ','.join(UserNames),
    }

    request = urllib.Request(url = url, data = json.dumps(params))
    request.add_header('ContentType', 'application/json; charset=UTF-8')
    response = urllib.urlopen(request)
    data = response.read()

    # print data

    dic = json.loads(data)
    ErrMsg = dic['BaseResponse']['ErrMsg']
    if len(ErrMsg) > 0:
        print(ErrMsg)

    Ret = dic['BaseResponse']['Ret']
    if Ret != 0:
        return False
        
    return True 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:27,代码来源:weixin - 3.py

示例4: getUUID

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def getUUID():
    global uuid

    url = 'https://login.weixin.qq.com/jslogin'
    params = {
        'appid': 'wx782c26e4c19acffb',
        'fun': 'new',
        'lang': 'zh_CN',
        '_': int(time.time()),
    }

    request = urllib.Request(url = url, data = urllib.urlencode(params))
    response = urllib.urlopen(request)
    data = response.read()

    # print data

    # window.QRLogin.code = 200; window.QRLogin.uuid = "oZwt_bFfRg==";
    regx = r'window.QRLogin.code = (\d+); window.QRLogin.uuid = "(\S+?)"'
    pm = re.search(regx, data)

    code = pm.group(1)
    uuid = pm.group(2)

    if code == '200':
        return True

    return False 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:30,代码来源:weixin - 3.py

示例5: showQRImage

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def showQRImage():
    global tip

    url = 'https://login.weixin.qq.com/qrcode/' + uuid
    params = {
        't': 'webwx',
        '_': int(time.time()),
    }

    request = urllib.Request(url = url, data = urllib.urlencode(params))
    response = urllib.urlopen(request)

    tip = 1

    f = open(QRImagePath, 'wb')
    f.write(response.read())
    f.close()

    if sys.platform.find('darwin') >= 0:
        os.system('open %s' % QRImagePath)
    elif sys.platform.find('linux') >= 0:
        os.system('xdg-open %s' % QRImagePath)
    else:
        os.system('call %s' % QRImagePath)

    print('请使用微信扫描二维码以登录') 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:28,代码来源:weixin - 3.py

示例6: waitForLogin

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def waitForLogin():
    global tip, base_uri, redirect_uri

    url = 'https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s' % (tip, uuid, int(time.time()))

    request = urllib.Request(url = url)
    response = urllib.urlopen(request)
    data = response.read()
    
    # print data

    # window.code=500;
    regx = r'window.code=(\d+);'
    pm = re.search(regx, data)

    code = pm.group(1)

    if code == '201': #已扫描
        print('成功扫描,请在手机上点击确认以登录')
        tip = 0
    elif code == '200': #已登录
        print('正在登录...')
        regx = r'window.redirect_uri="(\S+?)";'
        pm = re.search(regx, data)
        redirect_uri = pm.group(1) + '&fun=new'
        base_uri = redirect_uri[:redirect_uri.rfind('/')]
    elif code == '408': #超时
        pass
    # elif code == '400' or code == '500':

    return code 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:33,代码来源:weixin - 3.py

示例7: webwxinit

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def webwxinit():

    url = base_uri + '/webwxinit?pass_ticket=%s&skey=%s&r=%s' % (pass_ticket, skey, int(time.time()))
    params = {
        'BaseRequest': BaseRequest
    }

    request = urllib.Request(url = url, data = json.dumps(params))
    request.add_header('ContentType', 'application/json; charset=UTF-8')
    response = urllib.urlopen(request)
    data = response.read()

    if DEBUG == True:
        f = open(os.getcwd() + '/webwxinit.json', 'wb')
        f.write(data)
        f.close()

    # print data

    global ContactList, My
    dic = json.loads(data)
    ContactList = dic['ContactList']
    My = dic['User']

    ErrMsg = dic['BaseResponse']['ErrMsg']
    if len(ErrMsg) > 0:
        print(ErrMsg)

    Ret = dic['BaseResponse']['Ret']
    if Ret != 0:
        return False
        
    return True 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:35,代码来源:weixin - 3.py

示例8: createChatroom

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def createChatroom(UserNames):
    MemberList = []
    for UserName in UserNames:
        MemberList.append({'UserName': UserName})


    url = base_uri + '/webwxcreatechatroom?pass_ticket=%s&r=%s' % (pass_ticket, int(time.time()))
    params = {
        'BaseRequest': BaseRequest,
        'MemberCount': len(MemberList),
        'MemberList': MemberList,
        'Topic': '',
    }

    request = urllib.Request(url = url, data = json.dumps(params))
    request.add_header('ContentType', 'application/json; charset=UTF-8')
    response = urllib.urlopen(request)
    data = response.read()

    # print data

    dic = json.loads(data)
    ChatRoomName = dic['ChatRoomName']
    MemberList = dic['MemberList']
    DeletedList = []
    for Member in MemberList:
        if Member['MemberStatus'] == 4: #被对方删除了
            DeletedList.append(Member['UserName'])

    ErrMsg = dic['BaseResponse']['ErrMsg']
    if len(ErrMsg) > 0:
        print(ErrMsg)

    return (ChatRoomName, DeletedList) 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:36,代码来源:weixin - 3.py

示例9: addMember

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def addMember(ChatRoomName, UserNames):
    url = base_uri + '/webwxupdatechatroom?fun=addmember&pass_ticket=%s' % (pass_ticket)
    params = {
        'BaseRequest': BaseRequest,
        'ChatRoomName': ChatRoomName,
        'AddMemberList': ','.join(UserNames),
    }

    request = urllib.Request(url = url, data = json.dumps(params))
    request.add_header('ContentType', 'application/json; charset=UTF-8')
    response = urllib.urlopen(request)
    data = response.read()

    # print data

    dic = json.loads(data)
    MemberList = dic['MemberList']
    DeletedList = []
    for Member in MemberList:
        if Member['MemberStatus'] == 4: #被对方删除了
            DeletedList.append(Member['UserName'])

    ErrMsg = dic['BaseResponse']['ErrMsg']
    if len(ErrMsg) > 0:
        print(ErrMsg)

    return DeletedList 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:29,代码来源:weixin - 3.py

示例10: request

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def request(self, host, handler, request_body, verbose):
        self.verbose = verbose
        url = 'http://{0}{1}'.format(host, handler)
        request = urllib.Request(url)
        request.add_data(request_body)
        request.add_header("User-Agent", self.user_agent)
        request.add_header("Content-Type", "text/html")
        f = urllib.urlopen(request)
        return self.parse_response(f) 
开发者ID:fedora-python,项目名称:pyp2rpm,代码行数:11,代码来源:convertor.py

示例11: login

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def login():
    global skey, wxsid, wxuin, pass_ticket, BaseRequest

    request = urllib.Request(url = redirect_uri)
    response = urllib.urlopen(request)
    data = response.read()

    # print data

    '''
        <error>
            <ret>0</ret>
            <message>OK</message>
            <skey>xxx</skey>
            <wxsid>xxx</wxsid>
            <wxuin>xxx</wxuin>
            <pass_ticket>xxx</pass_ticket>
            <isgrayscale>1</isgrayscale>
        </error>
    '''

    doc = xml.dom.minidom.parseString(data)
    root = doc.documentElement

    for node in root.childNodes:
        if node.nodeName == 'skey':
            skey = node.childNodes[0].data
        elif node.nodeName == 'wxsid':
            wxsid = node.childNodes[0].data
        elif node.nodeName == 'wxuin':
            wxuin = node.childNodes[0].data
        elif node.nodeName == 'pass_ticket':
            pass_ticket = node.childNodes[0].data

    # print 'skey: %s, wxsid: %s, wxuin: %s, pass_ticket: %s' % (skey, wxsid, wxuin, pass_ticket)

    if skey == '' or wxsid == '' or wxuin == '' or pass_ticket == '':
        return False

    BaseRequest = {
        'Uin': int(wxuin),
        'Sid': wxsid,
        'Skey': skey,
        'DeviceID': deviceId,
    }

    return True 
开发者ID:DannyVim,项目名称:ToolsCollection,代码行数:49,代码来源:weixin - 3.py

示例12: _requestUrl

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import Request [as 别名]
def _requestUrl(self,
                    url,
                    method,
                    data=None):
        """Request an URL.

        Args:
          url:
            The web location we want to retrieve.
          method:
            Either POST or GET.
          data:
            A dict of (str, unicode) key/value pairs.

        Returns:
          A JSON object.
        """

        if method == 'POST':
            if 'audio' in data and (isinstance(data['audio'], file) or 'http' in data['audio']) or \
               'document' in data and (isinstance(data['document'], file) or 'http' in data['document']) or \
               'photo' in data and (isinstance(data['photo'], file) or 'http' in data['photo']) or \
               'video' in data and (isinstance(data['video'], file) or 'http' in data['video']):
                try:
                    data = InputFile(data)
                    request = urllib.Request(
                        url,
                        data=data.to_form(),
                        headers=data.headers
                    )
                    return urllib.request.urlopen(request).read()
                except urllib.error.URLError as e:
                    raise TelegramError(str(e))
            else:
                try:
                    return urllib.request.urlopen(
                        url,
                        urllib.parse.urlencode(data).encode('utf8')
                    ).read()
                #except urllib.IOError as e:
                #    raise TelegramError(str(e))
                except urllib.error.URLError as e:
                    raise TelegramError(str(e))

        if method == 'GET':
            try:
                return urllib.request.urlopen(url).read()
            except urllib.error.URLError as e:
                raise TelegramError(str(e))
        return 0 
开发者ID:btseytlin,项目名称:dungeon_bot,代码行数:52,代码来源:bot.py


注:本文中的urllib.Request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。