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


Python Request.get_selector方法代码示例

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


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

示例1: get1

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_selector [as 别名]
  def get1(self, url, maxretry=3, maxredirect=3):
    if self.debug:
      print >>stderr, 'GET: %r' % url
    # loop
    for rtry in range(maxredirect):
      # forge urllib2.Request object.
      req = Request(url)
      # add cookie headers if necessary.
      if self.cookiejar:
        self.cookiejar.add_cookie_header(req)
        headers = req.unredirected_hdrs
        headers.update(self.HEADERS)
      else:
        headers = self.HEADERS
      # get response.
      for ctry in range(maxretry):
        try:
          if not self.conn:
            print >>stderr, 'Making connection: %r...' % (self.hostport,)
            self.conn = HTTPConnection(self.hostport)
          self.conn.request('GET', req.get_selector().replace(' ',''), '', headers)
	  self.conn.sock.settimeout(self.timeout)
          resp = self.conn.getresponse()
          break
        except BadStatusLine, x:
          # connection closed unexpectedly
          print >>stderr, 'Connection closed unexpectedly.'
          # it restarts the connection...
          self.conn.close()
          self.conn = None
        except socket.error, x:
          # connection closed unexpectedly
          print >>stderr, 'Socket error:', x
          self.conn.close()
          self.conn = None
开发者ID:dreamfrog,项目名称:jophiel,代码行数:37,代码来源:textcrawler.py

示例2: sign_request

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_selector [as 别名]
def sign_request(request, secret_key):
	req = Request(request)
	raw = "%s\n%s\n%s\n%s" % (req.get_method(),req.get_host(),req.get_selector().split('?')[0],req.get_selector().split('?')[1])
	key = bytes(secret_key)
	print(raw)
	hashed = hmac.new(key, raw, sha1)
	signature = binascii.b2a_base64(hashed.digest())
	return request + '&signature=%s' % quote(signature, '\n')
开发者ID:stodd,项目名称:hmac-python,代码行数:10,代码来源:hmac_sign.py

示例3: test_urlwith_fragment

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_selector [as 别名]
 def test_urlwith_fragment(self):
     req = Request("http://www.python.org/?qs=query#fragment=true")
     self.assertEqual("/?qs=query", req.get_selector())
     req = Request("http://www.python.org/#fun=true")
     self.assertEqual("/", req.get_selector())
开发者ID:321boom,项目名称:The-Powder-Toy,代码行数:7,代码来源:test_urllib2.py


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