Ejemplo n.º 1
0
 def parseNIPIC(self, url, choice):
     items = []
     self.log.info(u'Python 请求 URL:%s ' % url)
     url = u'http://' + url  #nipic不需要将中文转化为16进制表示
     htmlContent = self.getResponseContent(url)
     soup = BeautifulSoup(htmlContent, 'lxml')
     try:
         tagsli = soup.find_all('img', attrs={'class': 'lazy'})
         for tag in tagsli:
             item = image()
             item.descrurl = tag.find_parent(
                 'a').attrs['href'] if tag != None else None
             item.thumburl = tag.attrs[
                 'data-original'] if tag != None else None
             item.description = tag.attrs['alt'] if tag != None else None
             if (choice == GET_REAL_IMG):  #需要获取原图则再次解析下载原图下载地址
                 item.downurl = 'restrict'
                 items.append(item)
             else:
                 items.append(item)
             item.show()
             item.save()
         self.log.info(u'Python 解析URL:%s 完成' % url)
     except:
         self.log.error(u'Python 解析 URL:%s 错误' % url)
         return None
     else:
         return items
Ejemplo n.º 2
0
 def parseSCCNN(self, url, choice):
     items = []
     self.log.info(u'Python 请求 URL:%s ' % url)
     url = u'http://' + urllib.pathname2url(
         url.encode('utf-8'))  #将带中文的url 转换为 %十六进制 形式
     htmlContent = self.getResponseContent(url)
     soup = BeautifulSoup(htmlContent, 'lxml')
     try:
         content = soup.find('table',
                             attrs={'style': 'BORDER-COLLAPSE: collapse'})
         tagsli = content.find_all(
             'img', attrs={'border': '0'}) if content != None else None
         for tag in tagsli:
             item = image()
             item.descrurl = tag.find_parent(
                 'a', attrs={
                     'target': '_blank'
                 }).attrs['href'] if tag != None else None
             item.thumburl = tag.attrs['src'] if tag != None else None
             item.description = tag.attrs['alt'] if tag != None else None
             if (choice == GET_REAL_IMG):  #需要获取原图则再次解析下载原图下载地址
                 item.downurl = self.getOriginNIPICURL(item.descrurl)
                 if item.downurl != None:
                     items.append(item)
             else:
                 items.append(item)
         self.log.info(u'Python 解析URL:%s 完成' % url)
     except:
         self.log.error(u'Python 解析 URL:%s 错误' % url)
         return None
     else:
         return items
def image(request):
  '''
    /image?gnubgid=ZrsFAFju3QECCA%3AAgEAAAAAAAAA&height=450&width=600&css=deutsche&format=png

  '''

  try:
    img = model.image(
      request.args.get('gnubgid'),
      request.args.get('css'),
      request.args.get('format'),
      int(request.args.get('width')),
      int(request.args.get('height')),
    )
  except PossibleBadRequest, e:
    raise BadRequest(str(e))
def gnubg(request):
  '''
    /gnubg?pid= ZrsFAFju3QECCA&mid=AgEAAAAAAAAA&height=450&width=600&css=deutsche&format=png

  '''

  gnubgid = request.args.get('pid')+':'+request.args.get('mid')

  try:
    img = model.image(
      gnubgid,
      request.args.get('css'),
      request.args.get('format'),
      int(request.args.get('width')),
      int(request.args.get('height')),
    )
  except PossibleBadRequest, e:
    raise BadRequest(str(e))
Ejemplo n.º 5
0
import model

while True:

    command = input()
    parameters = command.split()

    if parameters[0] == "cwd":
        model.cwd()

    elif parameters[0] == "browser":
        if (len(parameters) == 1):
            model.browser()
        else:
            model.browser(parameters[1])

    elif parameters[0] == "search":
        model.search(parameters[1:])

    elif parameters[0] == "image":
        model.image(parameters[1:])

    else:
        print("Invalid option")