Python mechanize 模块,ParseFile() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用mechanize.ParseFile()

项目:whatbetter    作者:pthcode    | 项目源码 | 文件源码
def upload(self, group, torrent, new_torrent, format, description=[]):
        url = "https://what.cd/upload.php?groupid=%s" % group['group']['id']
        response = self.session.get(url)
        forms = mechanize.ParseFile(StringIO(response.text.encode('utf-8')), url)
        form = forms[-1]
        form.find_control('file_input').add_file(open(new_torrent), 'application/x-bittorrent', os.path.basename(new_torrent))
        if torrent['remastered']:
            form.find_control('remaster').set_single('1')
            form['remaster_year'] = str(torrent['remasterYear'])
            form['remaster_title'] = torrent['remasterTitle']
            form['remaster_record_label'] = torrent['remasterRecordLabel']
            form['remaster_catalogue_number'] = torrent['remasterCatalogueNumber']

        form.find_control('format').set('1', formats[format]['format'])
        form.find_control('bitrate').set('1', formats[format]['encoding'])
        form.find_control('media').set('1', torrent['media'])

        release_desc = '\n'.join(description)
        if release_desc:
            form['release_desc'] = release_desc

        _, data, headers = form.click_request_data()
        return self.session.post(url, data=data, headers=dict(headers))
项目:REDBetter-crawler    作者:Mechazawa    | 项目源码 | 文件源码
def upload(self, group, torrent, new_torrent, format, description=[]):
        url = "https://redacted.ch/upload.php?groupid=%s" % group['group']['id']
        response = self.session.get(url)
        forms = mechanize.ParseFile(StringIO(response.text.encode('utf-8')), url)
        form = forms[-1]
        form.find_control('file_input').add_file(open(new_torrent), 'application/x-bittorrent', os.path.basename(new_torrent))
        if torrent['remastered']:
            form.find_control('remaster').set_single('1')
            form['remaster_year'] = str(torrent['remasterYear'])
            form['remaster_title'] = torrent['remasterTitle']
            form['remaster_record_label'] = torrent['remasterRecordLabel']
            form['remaster_catalogue_number'] = torrent['remasterCatalogueNumber']

        form.find_control('format').set('1', formats[format]['format'])
        form.find_control('bitrate').set('1', formats[format]['encoding'])
        form.find_control('media').set('1', torrent['media'])

        release_desc = '\n'.join(description)
        if release_desc:
            form['release_desc'] = release_desc

        _, data, headers = form.click_request_data()
        return self.session.post(url, data=data, headers=dict(headers))
项目:nwbetter    作者:defmulti    | 项目源码 | 文件源码
def upload(self, group, torrent, new_torrent, format, description=[]):
        url = "https://notwhat.cd/upload.php?groupid=%s" % group['group']['id']
        response = self.session.get(url)
        forms = mechanize.ParseFile(StringIO(response.text.encode('utf-8')), url)
        form = forms[-1]
        form.find_control('file_input').add_file(open(new_torrent), 'application/x-bittorrent', os.path.basename(new_torrent))
        if torrent['remastered']:
            form.find_control('remaster').set_single('1')
            form['remaster_year'] = str(torrent['remasterYear'])
            form['remaster_title'] = torrent['remasterTitle']
            form['remaster_record_label'] = torrent['remasterRecordLabel']
            form['remaster_catalogue_number'] = torrent['remasterCatalogueNumber']

        form.find_control('format').set('1', formats[format]['format'])
        form.find_control('bitrate').set('1', formats[format]['encoding'])
        form.find_control('media').set('1', torrent['media'])

        release_desc = '\n'.join(description)
        if release_desc:
            form['release_desc'] = release_desc

        _, data, headers = form.click_request_data()
        return self.session.post(url, data=data, headers=dict(headers))
项目:whatbetter    作者:pthcode    | 项目源码 | 文件源码
def set_24bit(self, torrent):
        url = "https://what.cd/torrents.php?action=edit&id=%s" % torrent['id']
        response = self.session.get(url)
        forms = mechanize.ParseFile(StringIO(response.text.encode('utf-8')), url)
        form = forms[-3]
        form.find_control('bitrate').set('1', '24bit Lossless')
        _, data, headers = form.click_request_data()
        return self.session.post(url, data=data, headers=dict(headers))
项目:REDBetter-crawler    作者:Mechazawa    | 项目源码 | 文件源码
def set_24bit(self, torrent):
        url = "https://redacted.ch/torrents.php?action=edit&id=%s" % torrent['id']
        response = self.session.get(url)
        forms = mechanize.ParseFile(StringIO(response.text.encode('utf-8')), url)
        form = forms[-3]
        form.find_control('bitrate').set('1', '24bit Lossless')
        _, data, headers = form.click_request_data()
        return self.session.post(url, data=data, headers=dict(headers))
项目:nwbetter    作者:defmulti    | 项目源码 | 文件源码
def set_24bit(self, torrent):
        url = "https://notwhat.cd/torrents.php?action=edit&id=%s" % torrent['id']
        response = self.session.get(url)
        forms = mechanize.ParseFile(StringIO(response.text.encode('utf-8')), url)
        form = forms[-1]
        form.find_control('bitrate').set('1', '24bit Lossless')
        _, data, headers = form.click_request_data()
        return self.session.post(url, data=data, headers=dict(headers))