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


Python Browser.title方法代码示例

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


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

示例1: login_and_authorize

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def login_and_authorize(argv=None):
    if argv is None:
       argv = sys.argv
    
    authorize_url = argv[1]
    config = json.loads(argv[2])
    
    print "AUTHORIZING", authorize_url
    br = Browser()
    br.set_debug_redirects(True)
    br.open(authorize_url)
    
    print "FIRST PAGE", br.title(), br.geturl()
    br.select_form(nr=2)
    br["login_email"] = config[u"testing_user"]
    br["login_password"] = config[u"testing_password"]

    resp = br.submit()
    print "RESULT PAGE TITLE", br.title()
    print "RESULT URL", resp.geturl()

    assert br.viewing_html(), "Looks like it busted."

    try:
        br.select_form(nr=2)
        br.submit()
        assert br.viewing_html(), "Looks like it busted."
        assert "API Request Authorized" in br.title(), "Title Is Wrong (bad email/password?): %r at %r" % (br.title(), br.geturl())
    except FormNotFoundError:
        print "Looks like we're blessed."
    
    return "OK"
开发者ID:Rendez,项目名称:node-dropbox,代码行数:34,代码来源:token_authorize.py

示例2: login_and_authorize

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def login_and_authorize(authorize_url, config):
    print "AUTHORIZING", authorize_url

    br = Browser()
    br.set_debug_redirects(True)
    br.open(authorize_url)
    print "FIRST PAGE", br.title(), br.geturl()

    br.select_form(nr=1)
    br['login_email'] = config['testing_user']
    br['login_password'] = config['testing_password']

    resp = br.submit()
    print "RESULT PAGE TITLE", br.title()
    print "RESULT URL", resp.geturl()

    assert br.viewing_html(), "Looks like it busted."

    try:
        br.select_form(nr=1)
        br.submit()
        br.viewing_html(), "Looks like it busted."
        assert "API Request Authorized" in br.title(), "Title Is Wrong (bad email/password?): %r at %r" % (br.title(), br.geturl())
    except FormNotFoundError:
        print "Looks like we're blessed."
开发者ID:racktivity,项目名称:ext-pylabs-core,代码行数:27,代码来源:helpers.py

示例3: login_to_kaggle

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
    def login_to_kaggle(self):  
        """ Login to Kaggle website
        Parameters:
        -----------
        None
        
        Returns:
        browser: Browser
            a mechanizer Browser object to be used for further access to site
        """          
        
        if self.verbose:
            print("Logging in to Kaggle..."),

        br = Browser()
        cj = cookielib.LWPCookieJar()
        br.set_cookiejar(cj)
        
        br.open(self.kag_login_url)
        
        br.select_form(nr=0)
        br['UserName'] = self.kag_username
        br['Password'] = self.kag_password
        br.submit(nr=0)
        
        if br.title() == "Login | Kaggle":
            raise KaggleError("Unable to login Kaggle with username %s (response title: %s)" % (self.kag_username,br.title()))
        
        if self.verbose:
            print("done!")
        
        return br
开发者ID:joostgp,项目名称:ml_toolbox,代码行数:34,代码来源:kaggle.py

示例4: main

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def main():
  # Command line options.
  parser = optparse.OptionParser('usage: %prog [options]')
  parser.add_option('--unread', dest='unread', action='store_true',
                    default=False, help='Only tag unread items')
  (opts, args) = parser.parse_args()

  # Get all items.
  api = readitlater.API(configs.RIL_APIKEY, configs.RIL_USERNAME,
                        configs.RIL_PASSWORD)
  items = api.get(state=('unread' if opts.unread else None))
  list = items['list']

  br = Browser()

  # Iterate over items.
  for k, v in list.items():
      #if v['title'] == v['url']:
      if not v['title']:
          print u'Found: {0} ({1})'.format(v['title'], v['url']);
          try:
              doc = br.open(v['url']);
          except urllib2.HTTPError, e:
              print u'Error fetching page: {0}'.format(e.code)
              continue

          if not br.viewing_html():
              print u'Not a HTML file!'
          else:
              title = br.title();
              print u'New title: {0}'.format(title.decode('ascii', 'ignore'))
              # Send the new tags to RIL.
              api.send(update_title=[{'url': v['url'], 'title': title}])
开发者ID:ngaloppo,项目名称:ril-title-grabber,代码行数:35,代码来源:title_grabber.py

示例5: url_handler

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def url_handler(data, lock):
    tweet = json.loads(data)
    if tweet['entities']['urls']:
        for index in range(len(tweet['entities']['urls'])):
            url = tweet['entities']['urls'][index]['expanded_url']
            try:
                tweet['entities']['urls'][index]['url_title'] = "-"
                br = Browser()
                br.open(url)
                title = br.title()
                if title == None:
                    title = "-"
                tweet['entities']['urls'][index]['url_title'] = title.encode('ascii','ignore')
            
            except (BrowserStateError, ParseError, UnicodeDecodeError, URLError):
                pass
    else:
        tweet
    lock.acquire()
    try:    
        try:
            global count
            f = open('json/tweets-' + str(count) + '.json', 'a')
            if f.tell() >= 9900000:
                f.close()
                count += 1
                f = open('json/tweets-' + str(count) + '.json', 'a')
            f.write(json.dumps(tweet) + "\n")
            f.close()
        except UnicodeDecodeError, e: 
            pass
    finally:
        lock.release()
开发者ID:christian91cruz,项目名称:Twitter-Search-Engine-and-Data-Retrieval,代码行数:35,代码来源:gatherTweets.py

示例6: populate

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def populate(filename, page_category):
    file_path = urls_dir + filename
    page_urls = open(file_path, 'r')
    next_url = page_urls.readline()[:-1]
    cat = Category.objects.get(category = page_category)
    # Set up browser object. robots.txt causes problems, so it is disabled.
    br = Browser()
    br.set_handle_robots(False)
    # While the URLs file still has URLs
    while next_url != "":
        # Check if the given webpage still exists. If so, pull out the webpage <title> element and store it.
        try:
            br.open(next_url, timeout=5)
            exists = True
            title = safe_unicode(br.title())
            if title is None:
                title = 'Untitled page'
            print "Found: " + title
        # Exceptions to handle 403, 404, 503 errors and pages that cannot be parsed
        except HTTPError, e:
            print 'HTTP Error: ' + str(e)
            exists = False
        except URLError, e:
            print 'URL Error: ' + str(e)
            exists = False
开发者ID:Loptr250,项目名称:ifind,代码行数:27,代码来源:populate_screenshots.py

示例7: fetch

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def fetch():
    br = Browser()                # Create a browser
    map = {};
    
    # br.open(login_url)            # Open the login page
    # br.select_form(id="signform")  # Find the login form
    # br['username'] = username     # Set the form values
    # br['password'] = password
    # resp = br.submit()            # Submit the form
    
    br.open('http://www.verycd.com/sto/music/china/')
    nice_links = [l for l in br.links()
                    if 'topics' in l.url]
    if not nice_links:
        return None
    
    for link in nice_links:
        if link.url in map.keys():
            continue
        
        try:
            response = br.follow_link(link)
            map[link.url] = br.title()
        except Exception, e:
            print >> sys.stderr, e
开发者ID:mahone3297,项目名称:hades,代码行数:27,代码来源:EgMechanize.py

示例8: get_title

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
 def get_title(self, url):
   '''
   Return the title of the passed
   in URL.
   '''
   br = Browser()
   br.set_handle_robots(False)
   br.open(url)
   return 'Title: {}'.format(br.title())
开发者ID:genericpersona,项目名称:GGM,代码行数:11,代码来源:URLUtils.py

示例9: main

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def main():
    cj = cookielib.LWPCookieJar('cookie.txt')
    try:
        cj.load('cookie.txt')
    except IOError:
        print "Кукисы не найдены"
    root_url = 'http://188.134.114.45/store1/admin/'
    admin_url ='http://188.134.114.45/store1/admin/index.php?route=common/home&token='
    suppler_url = "http://188.134.114.45/store1/admin/index.php?route=catalog/suppler/update&token="
    orinon1_url = '&suppler_id=1'
    orinon2_url = '&suppler_id=2'
    username = 'admin'
    userpass = '1q2w'
    br = Browser()
    br.set_handle_robots(False)
    br.set_cookiejar(cj)
    br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6')]
    home_page = br.open(root_url)

    print br.title()


    br.select_form(nr=0)
    br["username"] = username
    br["password"] = userpass
    br.submit()
    token = getToken(br.geturl())
    cj.save('cookie.txt')

    br.open(suppler_url + token + orinon1_url)
    br.select_form(nr = 1)
    control = br.form.find_control("command")
    control.set_value_by_label(("Удалить товары",))

    res = br.submit()


    br.open(suppler_url + token + orinon2_url)
    br.select_form(nr = 1)
    control = br.form.find_control("command")
    control.set_value_by_label(("Удалить товары",))

    res = br.submit()
开发者ID:CoderGosha,项目名称:UpdateDiscounter,代码行数:45,代码来源:main.py

示例10: find_title

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
 def find_title(self, url):
     """
     This finds the title when provided with a string of a URL.
     """
     br = Browser()
     br.open(url)
     title = br.title()
     if(title):            
         return title
     else:        
         return False
开发者ID:mikemike,项目名称:SkypeBot,代码行数:13,代码来源:titles.py

示例11: fetch

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
def fetch():
    result_no = 0                 # Number the output files
    br = Browser()                # Create a browser
    br.open(LOGIN_URL)            # Open the login page
    br.select_form(name="login")  # Find the login form
    br['username'] = USERNAME     # Set the form values
    br['password'] = PASSWORD
    resp = br.submit()            # Submit the form

    # Automatic redirect sometimes fails, follow manually when needed
    if 'Redirecting' in br.title():
        resp = br.follow_link(text_regex='click here')

    # Loop through the searches, keeping fixed query parameters
    for actor in in VARIABLE_QUERY:
        # I like to watch what's happening in the console
        print >> sys.stderr, '***', actor
        # Lets do the actual query now
        br.open(SEARCH_URL + FIXED_QUERY + actor)
        # The query actually gives us links to the content pages we like,
        # but there are some other links on the page that we ignore
        nice_links = [l for l in br.links()
                        if 'good_path' in l.url
                        and 'credential' in l.url]
        if not nice_links:        # Maybe the relevant results are empty
            break
        for link in nice_links:
            try:
                response = br.follow_link(link)
                # More console reporting on title of followed link page
                print >> sys.stderr, br.title()
                # Increment output filenames, open and write the file
                result_no += 1
                out = open(result_%04d % result_no, 'w')
                print >> out, response.read()
                out.close()
            # Nothing ever goes perfectly, ignore if we do not get page
            except mechanize._response.httperror_seek_wrapper:
                print >> sys.stderr, "Response error (probably 404)"
            # Let's not hammer the site too much between fetches
            time.sleep(1)
开发者ID:Wingman639,项目名称:python_tips,代码行数:43,代码来源:example_1.py

示例12: inferTitleFromURL

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
 def inferTitleFromURL(self, url):
     from mechanize import Browser
     from urlparse import urlparse
     try:
         result = urlparse(url)
         if result.scheme not in ['http', 'https']:
             return None
         browser = Browser()
         browser.open(url)
         return unicode(browser.title(), 'utf8')
     except Exception as e:
         NSLog("Exception: " + str(e))
         return None
开发者ID:Mondego,项目名称:pyreco,代码行数:15,代码来源:allPythonContent.py

示例13: login_and_authorize

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
 def login_and_authorize(self, authorize_url):
     from mechanize import Browser, FormNotFoundError
     import getpass
     print "AUTHORIZING", authorize_url
     br = Browser()
     br.set_debug_redirects(True)
     br.open(authorize_url)
     print "FIRST PAGE", br.title(), br.geturl()
     br.select_form(nr=1)
     br['login_email'] = raw_input('Enter your dropbox email: ')
     br['login_password'] = getpass.getpass('Enter your dropbox password: ')
     resp = br.submit()
     print "RESULT PAGE TITLE", br.title()
     print "RESULT URL", resp.geturl()
     assert br.viewing_html(), "Looks like it busted."
     try:
         br.select_form(nr=1)
         br.submit()
         assert br.viewing_html(), "Looks like it busted."
         assert "API Request Authorized" in br.title(), "Title Is Wrong (bad email/password?): %r at %r" % (br.title(), br.geturl())
     except FormNotFoundError:
         print "Looks like we're blessed."
开发者ID:yuiseki,项目名称:python_postutil,代码行数:24,代码来源:dropbox_post.py

示例14: get_title

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
    def get_title(self):
        if self.title is not None:
            return self.title

        b = Browser()
        site = ".".join(map(lambda x: x.capitalize(), self.url.split("/")[2].replace("www.", "").split(".")[:-1]))
        try:
            b.open(self.url)
            return "[%s] %s" % (site.encode("Utf-8"), encoding_sucks(b.title()))
        except URLError:
            self.title = "[%s] Error: couldn't fetch the title" % site
            self.save()
            return self.title
开发者ID:Bouska,项目名称:rpselectator,代码行数:15,代码来源:models.py

示例15: __init__

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import title [as 别名]
class Lockerz:
    def __init__( self, name, password ):
        self.name = name
        self.password = password
        self.br = Browser()

    def connect( self ):
        self.br.open( "http://www.lockerz.com" )
        self.br.select_form( nr=0 )
        self.br["handle"] = self.name
        self.br["password"] = self.password

        self.br.submit()
        return "Lockerz : My Locker" in self.br.title()

    def answer_all( self, generator, recursive=False ):
        page = self.br.open( "http://www.lockerz.com/dailies" );
        self._answer_all( page, generator )
        # ..
        if recursive:
            i = 0
            while True:
                try:
                    i+=1
                    page = self.br.follow_link( text_regex="< Previous Posts" )
                    print "-- page %d" % i
                    self._answer_all( page, generator )
                except LinkNotFoundError:
                    break

    def answer( self, id, answer ):
        d = urllib.urlencode( { "id": id, "a": answer, "o": None } )
        r = self.br.open( "http://www.lockerz.com/daily/answer", d );
        print r.read()
        self.br.back()

    def getPTZ( self ):
        s = BeautifulSoup( self.br.open( "http://www.lockerz.com" ).read() )
        return s.find( "span", attrs={ "class": "ptz_value" } ).string
 
    def _answer_all( self, page, generator ):
        s = BeautifulSoup( page.read() )
        e = s.findAll( "div", attrs={ "class": re.compile( "dailiesEntry dailyIndex*" ) } )
        for i in e:
            try:
                self.answer( i["id"], generator.getRandomSentence() )
            except KeyError:
                print "Already answered ..."    
开发者ID:jackMort,项目名称:mechLockerz,代码行数:50,代码来源:lockerz.py


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