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


Python Request.close方法代码示例

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


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

示例1: __open

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import close [as 别名]
 def __open(self, url):
   req = Request(url, headers = {
     'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
     'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
     'Accept-Encoding': 'none',
     'Accept-Language': 'en-US,en;q=0.8',
     'Connection': 'keep-alive'})
   
   start = dt.now()
   
   req = None
   try:
     req = urlopen(url)
     self.html_src = req.read()
   except Exception as e:
     self.req_err = e
   else:
     if self.req_err is not None:
       req.close()
   
   self.req_time = dt.now() - start
     
   return self.html_src
开发者ID:rhewett,项目名称:nhlscrapi,代码行数:26,代码来源:nhlreq.py

示例2: urlopen

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import close [as 别名]
   print 'Logged in to FitDay. Saved cookie to '+COOKIE_FILE+'.'

# Download weight data
nexturl = 'https://www.fitday.com/fitness/WeightHistory.html'

while nexturl != '':
   # Load the cookie and visit the URL of interest.
   cookieJar.load(COOKIE_FILE)
   while True:
      try:
         req = urlopen(nexturl)
         break
      except:
         print "Error reading the URL. Trying again..."
   htmlSource = req.read()
   req.close()
   
   # Filter the result a bit.
   htmlSource = htmlSource[11:]
   htmlSource = htmlSource.replace('\\"','"')
   htmlSource = htmlSource.replace('\\n','\n')
   htmlSource = htmlSource.replace('\\t','\t')
   
   soup = BeautifulSoup(''.join(htmlSource))
   
   to_extract = soup.findAll('script') # removing JS
   for item in to_extract:
      item.extract()
   
   weight_table = soup.find('div', {'class' : 'ListView'}).table
   
开发者ID:btrettel,项目名称:medos,代码行数:32,代码来源:FitDay.py


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