小编Cho*_*pra的帖子

按Javascript数组中的出现次数(计数)排序

我是Jquery和Javascript的新手.有人可以根据数组中的出现次数(计数)帮助我进行Jquery排序.我尝试了各种排序方法,但没有一种方法有效.

我在Javascript中有一个数组

allTypesArray = ["4", "4","2", "2", "2", "6", "2", "6", "6"]

// here  2 is printed four times, 6 is printed thrice, and 4 is printed twice
Run Code Online (Sandbox Code Playgroud)

我需要像这样的输出

newTypesArray = ["2","6","4"]
Run Code Online (Sandbox Code Playgroud)

我试过了

function array_count_values(e) {
var t = {}, n = "",
    r = "";
var i = function (e) {
    var t = typeof e;
    t = t.toLowerCase();
    if (t === "object") {
        t = "array"
    }
    return t
};
var s = function (e) {
    switch (typeof …
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting jquery

4
推荐指数
2
解决办法
3198
查看次数

show_404()中的自定义视图无效

我已经尝试了404_override和MY_Exceptions来显示自定义错误视图.有人可以帮我吗?

这是404_override代码

routes.php文件

$route['404_override'] = 'error/index';
Run Code Online (Sandbox Code Playgroud)

Error.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Error extends CI_Controller {

    public $user_id ='';

    function __construct()
    {
        parent::__construct();
        $this->load->library('login.php');
        $user_Details = $this->login_library->get_user_details();
        $this->user_id = $user_Details['user_id'];
    }

    public function index()
    {
        $this->output->set_status_header('404');
         $this->output->set_status_header('404');  
        $this->load->view('view_header',$this->user_id); 
        $this->load->view('view_404');
        $this->load->view('view_footer',$this->user_id);     
    }



}
Run Code Online (Sandbox Code Playgroud)

这是My_Exceptions代码

<?php  if (! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Exceptions extends CI_Exceptions{

    function MY_Exceptions(){
        parent::CI_Exceptions();
        $this->CI =& get_instance();
    }

    function show_404($page=''){ 
        echo $heading = "404 Page Not Found";
        echo $message …
Run Code Online (Sandbox Code Playgroud)

error-handling routing codeigniter exception http-status-code-404

3
推荐指数
1
解决办法
1万
查看次数

使用Python中的BeautifulSoup从脚本标签中提取文本

您能帮我解决这个小问题吗?我正在寻找使用美丽的汤(Python)从以下代码中的SCRIPT标记(不在正文中)提取电子邮件,电话和姓名值。我是Python的新手,并且博客建议使用Beautiful汤进行提取。

我尝试使用以下代码获取页面-

fileDetails = BeautifulSoup(urllib2.urlopen('http://www.example.com').read())
results = fileDetails.find(email:")
Run Code Online (Sandbox Code Playgroud)

该Ajax请求代码不再在页面中重复。我们还可以编写try and catch以便在页面中未找到它时不会引发任何错误。

<script type="text/javascript" language='javascript'> 
$(document).ready( function (){

   $('#message').click(function(){
       alert();
   });

    $('#addmessage').click(function(){
        $.ajax({ 
            type: "POST",
            url: 'http://www.example.com',
            data: { 
                email: 'abc@g.com', 
                phone: '9999999999', 
                name: 'XYZ'
            }
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

一旦得到这个,我也想存储在一个excel文件中。

谢谢您的期待。

python urllib2 beautifulsoup

3
推荐指数
2
解决办法
1万
查看次数

使用Python中的XLWT在Excel中追加行

如何在Python中使用XLWT或XLRD查找总行数?我有一个excel文件(accounts.xls),并希望在其中追加行.

我在这里收到错误 - AttributeError:'Sheet'对象没有属性'write'

from xlrd import open_workbook
from xlwt import Workbook
def saveWorkSpace(fields,r):
    wb = open_workbook('accounts.xls')
    ws = wb.sheet_by_index(0)
    r = ws.nrows
    r += 1
    wb = Workbook()
    ws.write(r,0,fields['name'])
    ws.write(r,1,fields['phone'])
    ws.write(r,2,fields['email'])
    wb.save('accounts.xls')
    print 'Wrote accounts.xls'
Run Code Online (Sandbox Code Playgroud)

python excel xlwt

0
推荐指数
1
解决办法
1万
查看次数