鍍金池/ 問答/ 數(shù)據(jù)分析&挖掘問答
夢一場 回答

希望提供 mini-reproducible 的例子,以及相關(guān)報錯信息。

大濕胸 回答

你的變量$ceshi好像錯了我改了一下,不知道對不對

//錯誤的
$ceshi='優(yōu)酷視頻$$第1集$http://v.youku.com/$youku#第2集$http://v.youku.com/v_show$youku#第3集$http://v.youku.com/$$$芒果視頻$$第1集$http://vmguo.com$mgtv#第2集$http://v.mangguo.com$mgtv#第3集$http://v.mangguo.com$mgtv';

//我?guī)湍阈薷牧?,其中少?youku這一部分
$ceshi='優(yōu)酷視頻$$第1集$http://v.youku.com/$youku#第2集$http://v.youku.com/v_show$youku#第3集$http://v.youku.com/$youku$$$芒果視頻$$第1集$http://vmguo.com$mgtv#第2集$http://v.mangguo.com$mgtv#第3集$http://v.mangguo.com$mgtv';

$result_array = array();

$temp = explode('$$$',$ceshi);
//var_dump($temp);
foreach($temp as $key=>$value){

    $temp_array = (explode('$$',$value));
    //當(dāng)前的類別
    $category = $temp_array[0];
    //內(nèi)容再次進行歸類
    $temp_array = explode('#',$temp_array[1]);
    foreach($temp_array as $key=>$value){
        
        //當(dāng)前的集數(shù)
        $temp_value = explode('$',$value);
        $ep_number = preg_replace('/(第)||(集)/','',$temp_value[0]);
        
        //需要壓入的數(shù)組
        $temp_result['siteSource']= $temp_value[2];
        $temp_result['siteName']= $category;
        $temp_result['siteLink']= $temp_value[1];
    
        //壓入結(jié)果數(shù)組
        $result_array["sitePerEpisode"][$ep_number][]=$temp_result;

    }
}

//$result_array為你要的結(jié)果,你可以var_dump看一下
//var_dump($result_array);

//將結(jié)果數(shù)組轉(zhuǎn)化為json,中文字符會被轉(zhuǎn)化
$json_result = json_encode($result_array,true);
echo $json_result;

未轉(zhuǎn)化為json的array結(jié)果

array(1) {
  ["sitePerEpisode"]=>
  array(3) {
    [1]=>
    array(2) {
      [0]=>
      array(3) {
        ["siteSource"]=>
        string(5) "youku"
        ["siteName"]=>
        string(12) "優(yōu)酷視頻"
        ["siteLink"]=>
        string(19) "http://v.youku.com/"
      }
      [1]=>
      array(3) {
        ["siteSource"]=>
        string(4) "mgtv"
        ["siteName"]=>
        string(12) "芒果視頻"
        ["siteLink"]=>
        string(16) "http://vmguo.com"
      }
    }
    [2]=>
    array(2) {
      [0]=>
      array(3) {
        ["siteSource"]=>
        string(5) "youku"
        ["siteName"]=>
        string(12) "優(yōu)酷視頻"
        ["siteLink"]=>
        string(25) "http://v.youku.com/v_show"
      }
      [1]=>
      array(3) {
        ["siteSource"]=>
        string(4) "mgtv"
        ["siteName"]=>
        string(12) "芒果視頻"
        ["siteLink"]=>
        string(20) "http://v.mangguo.com"
      }
    }
    [3]=>
    array(2) {
      [0]=>
      array(3) {
        ["siteSource"]=>
        string(5) "youku"
        ["siteName"]=>
        string(12) "優(yōu)酷視頻"
        ["siteLink"]=>
        string(19) "http://v.youku.com/"
      }
      [1]=>
      array(3) {
        ["siteSource"]=>
        string(4) "mgtv"
        ["siteName"]=>
        string(12) "芒果視頻"
        ["siteLink"]=>
        string(20) "http://v.mangguo.com"
      }
    }
  }
}
雨萌萌 回答

徑向漸變 定義若干顏色和透明,即形成若干同心圓。無需偽元素

朕略萌 回答

你好像忘記了提問題

夢一場 回答

我嘗試打開網(wǎng)站,打開調(diào)試頁面,并沒有自動進入debugger,你出現(xiàn)這個問題的原因可能是進入了你自己打的斷點。
加了我的調(diào)試頁面你可以看下。
圖片描述

何蘇葉 回答

用正則不是太推薦, 建議用標準的urllib庫來完成

>>>import urllib
>>>a = urllib.parse.parse_qs(urllib.parse.urlparse("http://abc.com/def?x=2&pn=2").query)
>>>a
{'x': ['2'], 'pn': ['2']}

或者用下面的方式直接獲得dict

>>>a = dict(urllib.parse.parse_qsl(urllib.parse.urlparse("http://abc.com/def?x=2&pn=2").query))
>>>a
{'x': '2', 'pn': '2'}
不討囍 回答

csdn上面的,直接搬了過來:

因為要做觀點,觀點的屋子類似于知乎的話題,所以得想辦法把他給爬下來,搞了半天最終還是妥妥的搞定了,代碼是python寫的,不懂得麻煩自學(xué)哈!懂得直接看代碼,絕對可用


#coding:utf-8
"""
@author:haoning
@create time:2015.8.5
"""
from __future__ import division  # 精確除法
from Queue import Queue
from __builtin__ import False
import json
import os
import re
import platform
import uuid
import urllib
import urllib2
import sys
import time
import MySQLdb as mdb
from bs4 import BeautifulSoup


reload(sys)
sys.setdefaultencoding( "utf-8" )


headers = {
   'User-Agent' : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0',
   'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
   'X-Requested-With':'XMLHttpRequest',
   'Referer':'https://www.zhihu.com/topics',
   'Cookie':'__utma=51854390.517069884.1416212035.1416212035.1416212035.1; q_c1=c02bf44d00d240798bfabcfc95baeb56|1455778173000|1416205243000; _za=b1c8ae35-f986-46a2-b24a-cb9359dc6b2a; aliyungf_tc=AQAAAJ1m71jL1woArKqF22VFnL/wRy6C; _xsrf=9d494558f9271340ab24598d85b2a3c8; cap_id="MDNiMjcwM2U0MTRhNDVmYjgxZWVhOWI0NTA2OGU5OTg=|1455864276|2a4ce8247ebd3c0df5393bb5661713ad9eec01dd"; n_c=1; _alicdn_sec=56c6ba4d556557d27a0f8c876f563d12a285f33a'
}


DB_HOST = '127.0.0.1'
DB_USER = 'root'
DB_PASS = 'root'


queue= Queue() #接收隊列
nodeSet=set()
keywordSet=set()
stop=0
offset=-20
level=0
maxLevel=7
counter=0
base=""


conn = mdb.connect(DB_HOST, DB_USER, DB_PASS, 'zhihu', charset='utf8')
conn.autocommit(False)
curr = conn.cursor()


def get_html(url):
    try:
        req = urllib2.Request(url)
        response = urllib2.urlopen(req,None,3) #在這里應(yīng)該加入代理
        html = response.read()
        return html
    except:
        pass
    return None


def getTopics():
    url = 'https://www.zhihu.com/topics'
    print url
    try:
        req = urllib2.Request(url)
        response = urllib2.urlopen(req) #鍦ㄨ繖閲屽簲璇ュ姞鍏ヤ唬鐞?
        html = response.read().decode('utf-8')
        print html
        soup = BeautifulSoup(html)
        lis = soup.find_all('li', {'class' : 'zm-topic-cat-item'})
        
        for li in lis:
            data_id=li.get('data-id')
            name=li.text
            curr.execute('select id from classify_new where name=%s',(name))
            y= curr.fetchone()
            if not y:
                curr.execute('INSERT INTO classify_new(data_id,name)VALUES(%s,%s)',(data_id,name))
        conn.commit()
    except Exception as e:
        print "get topic error",e
        


def get_extension(name):  
    where=name.rfind('.')
    if where!=-1:
        return name[where:len(name)]
    return None




def which_platform():
    sys_str = platform.system()
    return sys_str


def GetDateString():
    when=time.strftime('%Y-%m-%d',time.localtime(time.time()))
    foldername = str(when)
    return foldername 


def makeDateFolder(par,classify):
    try:
        if os.path.isdir(par):
            newFolderName=par + '//' + GetDateString() + '//'  +str(classify)
            if which_platform()=="Linux":
                newFolderName=par + '/' + GetDateString() + "/" +str(classify)
            if not os.path.isdir( newFolderName ):
                os.makedirs( newFolderName )
            return newFolderName
        else:
            return None 
    except Exception,e:
        print "kk",e
    return None 


def download_img(url,classify):
    try:
        extention=get_extension(url)
        if(extention is None):
            return None
        req = urllib2.Request(url)
        resp = urllib2.urlopen(req,None,3)
        dataimg=resp.read()
        name=str(uuid.uuid1()).replace("-","")+"_www.guandn.com"+extention
        top="E://topic_pic"
        folder=makeDateFolder(top, classify)
        filename=None
        if folder is not None:
            filename  =folder+"http://"+name
        try:
            if "e82bab09c_m" in str(url):
                return True
            if not os.path.exists(filename):
                file_object = open(filename,'w+b')
                file_object.write(dataimg)
                file_object.close()
                return '/room/default/'+GetDateString()+'/'+str(classify)+"/"+name
            else:
                print "file exist"
                return None
        except IOError,e1:
            print "e1=",e1
            pass
    except Exception as e:
        print "eee",e
        pass
    return None #如果沒有下載下來就利用原來網(wǎng)站的鏈接


def getChildren(node,name):
    global queue,nodeSet
    try:
        url="https://www.zhihu.com/topic/"+str(node)+"/hot"
        html=get_html(url)
        if html is None:
            return
        soup = BeautifulSoup(html)
        p_ch='父話題'
        node_name=soup.find('div', {'id' : 'zh-topic-title'}).find('h1').text
        topic_cla=soup.find('div', {'class' : 'child-topic'})
        if topic_cla is not None:
            try:
                p_ch=str(topic_cla.text)
                aList = soup.find_all('a', {'class' : 'zm-item-tag'}) #獲取所有子節(jié)點
                if u'子話題' in p_ch:
                    for a in aList:
                        token=a.get('data-token')
                        a=str(a).replace('\n','').replace('\t','').replace('\r','')
                        start=str(a).find('>')
                        end=str(a).rfind('</a>')
                        new_node=str(str(a)[start+1:end])
                        curr.execute('select id from rooms where name=%s',(new_node)) #先保證名字絕不相同
                        y= curr.fetchone()
                        if not y:
                            print "y=",y,"new_node=",new_node,"token=",token
                            queue.put((token,new_node,node_name))
            except Exception as e:
                print "add queue error",e
    except Exception as e:
        print "get html error",e
        
    


def getContent(n,name,p,top_id):
    try:
        global counter
        curr.execute('select id from rooms where name=%s',(name)) #先保證名字絕不相同
        y= curr.fetchone()
        print "exist?? ",y,"n=",n
        if not y:
            url="https://www.zhihu.com/topic/"+str(n)+"/hot"
            html=get_html(url)
            if html is None:
                return
            soup = BeautifulSoup(html)
            title=soup.find('div', {'id' : 'zh-topic-title'}).find('h1').text
            pic_path=soup.find('a',{'id':'zh-avartar-edit-form'}).find('img').get('src')
            description=soup.find('div',{'class':'zm-editable-content'})
            if description is not None:
                description=description.text
                
            if (u"未歸類" in title or u"根話題" in title): #允許入庫,避免死循環(huán)
                description=None
                
            tag_path=download_img(pic_path,top_id)
            print "tag_path=",tag_path
            if (tag_path is not None) or tag_path==True:
                if tag_path==True:
                    tag_path=None
                father_id=2 #默認為雜談
                curr.execute('select id from rooms where name=%s',(p))
                results = curr.fetchall()
                for r in results:
                    father_id=r[0]
                name=title
                curr.execute('select id from rooms where name=%s',(name)) #先保證名字絕不相同
                y= curr.fetchone()
                print "store see..",y
                if not y:
                    friends_num=0
                    temp = time.time()
                    x = time.localtime(float(temp))
                    create_time = time.strftime("%Y-%m-%d %H:%M:%S",x) # get time now
                    create_time
                    creater_id=None
                    room_avatar=tag_path
                    is_pass=1
                    has_index=0
                    reason_id=None  
                    #print father_id,name,friends_num,create_time,creater_id,room_avatar,is_pass,has_index,reason_id
                    ######################有資格入庫的內(nèi)容
                    counter=counter+1
                    curr.execute("INSERT INTO rooms(father_id,name,friends_num,description,create_time,creater_id,room_avatar,is_pass,has_index,reason_id)VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",(father_id,name,friends_num,description,create_time,creater_id,room_avatar,is_pass,has_index,reason_id))
                    conn.commit() #必須時時進入數(shù)據(jù)庫,不然找不到父節(jié)點
                    if counter % 200==0:
                        print "current node",name,"num",counter
    except Exception as e:
        print "get content error",e       


def work():
    global queue
    curr.execute('select id,node,parent,name from classify where status=1')
    results = curr.fetchall()
    for r in results:
        top_id=r[0]
        node=r[1]
        parent=r[2]
        name=r[3]
        try:
            queue.put((node,name,parent)) #首先放入隊列
            while queue.qsize() >0:
                n,p=queue.get() #頂節(jié)點出隊
                getContent(n,p,top_id)
                getChildren(n,name) #出隊內(nèi)容的子節(jié)點
            conn.commit()
        except Exception as e:
            print "what's wrong",e  
            
def new_work():
    global queue
    curr.execute('select id,data_id,name from classify_new_copy where status=1')
    results = curr.fetchall()
    for r in results:
        top_id=r[0]
        data_id=r[1]
        name=r[2]
        try:
            get_topis(data_id,name,top_id)
        except:
            pass




def get_topis(data_id,name,top_id):
    global queue
    url = 'https://www.zhihu.com/node/TopicsPlazzaListV2'
    isGet = True;
    offset = -20;
    data_id=str(data_id)
    while isGet:
        offset = offset + 20
        values = {'method': 'next', 'params': '{"topic_id":'+data_id+',"offset":'+str(offset)+',"hash_id":""}'}
        try:
            msg=None
            try:
                data = urllib.urlencode(values)
                request = urllib2.Request(url,data,headers)
                response = urllib2.urlopen(request,None,5)
                html=response.read().decode('utf-8')
                json_str = json.loads(html)
                ms=json_str['msg']
                if len(ms) <5:
                    break
                msg=ms[0]
            except Exception as e:
                print "eeeee",e
            #print msg
            if msg is not None:
                soup = BeautifulSoup(str(msg))
                blks = soup.find_all('div', {'class' : 'blk'})
                for blk in blks:
                    page=blk.find('a').get('href')
                    if page is not None:
                        node=page.replace("/topic/","") #將更多的種子入庫
                        parent=name
                        ne=blk.find('strong').text
                        try:
                            queue.put((node,ne,parent)) #首先放入隊列
                            while queue.qsize() >0:
                                n,name,p=queue.get() #頂節(jié)點出隊
                                size=queue.qsize()
                                if size > 0:
                                    print size
                                getContent(n,name,p,top_id)
                                getChildren(n,name) #出隊內(nèi)容的子節(jié)點
                            conn.commit()
                        except Exception as e:
                            print "what's wrong",e  
        except urllib2.URLError, e:
            print "error is",e
            pass 
            
        
if __name__ == '__main__':
    i=0
    while i<400:
        new_work()
        i=i+1

說下數(shù)據(jù)庫的問題,我這里就不傳附件了,看字段自己建立,因為這確實太簡單了,我是用的mysql,你看自己的需求自己建。

有什么不懂得麻煩去去轉(zhuǎn)盤網(wǎng)找我,因為這個也是我開發(fā)的,上面會及時更新qq群號,這里不留qq號啥的,以免被系統(tǒng)給K了。

風(fēng)畔 回答

MDN官網(wǎng)有這么一段話

clipboard.png

所以for...in在這里并不可靠
此處在循環(huán)前保存一個length,用下標遍歷就好了

焚音 回答

你的點擊事件是加在"駕駛員"這個span標簽上的

你的瞳 回答

re.search('(信)(.*?)(6)',str).group()

涼汐 回答

open的參數(shù)encoding設(shè)置成'utf-8'試試,如果反復(fù)換編碼都報錯,errors= 'ignore'(或'replace' )
還有用with語句吧,這樣不筆手動對文件對象close了
最后'html'不是好的變量命名

with open('douban.txt','w',encoding='utf-8',errors='replace') as f:
    f.write(html)
print( "寫入的內(nèi)容:",open('douban.txt','r').read() )
青檸 回答
int (*p)[5] = &arr;

你就可以理解成 *p 是 arr 的別名,也就是 p 的值等于 &arr。
所以你想要通過 p 獲取數(shù)組的值,需要 *(*p),這是第一個元素,第二個元素 *(*p + 1) 以此類推。

雨蝶 回答

代碼有小錯誤

$this->generateUniqueValidationCodes($number);

這里還得加上return
驗證碼字段需要唯一,好奇這個為什么要唯一?
唯一的話,你加上Unique Index好了

逗婦惱 回答

用正則表達式啊!你用正則計算兩個指定字符之間的字符,你那肯定是要獲取標簽里面的內(nèi)容吧!因為你抓下來的已經(jīng)不是html了,而是一個長長的字符串。我給你提供一個方法

var str = "1222223";
str = str.match(/1(\S*)3/)[1];
alert(str);//結(jié)果22222

就這么搞就ok了!我之前也搞過這種。

淚染裳 回答

一般是服務(wù)端獲取來訪客戶端的一些信息,比如:IP,remote_add還有你提到的FORWARDED_FOR等信息。

所以你想獲取某個代理IP的這些信息,可以這樣:
自己寫個小爬蟲(可以使用requests庫等),使用代理IP,來訪問自己一個web服務(wù)(比如用django寫的一個小站),這樣就可以在自己的web服務(wù)里面獲取到這個代理ip的header信息了。

心癌 回答

AC自動機是最好的選擇,效率足夠高??梢钥纯?a rel="nofollow noreferrer">https://github.com/vi3k6i5/fl... 這個庫,包含了查找和替換的AC自動機實現(xiàn)。

尛曖昧 回答

var data = {"result":[["分類名稱1","14818174"],["分類21","7431363"],["欄目2","7441546"],["欄目3","6376027"],["分類44","10221414"]]};

把data從前端post到php

<?php
$title_array = [];
foreach($_POST['data']['result'] as $title) {

$title_array[] = $title[0];

}

?>

柚稚 回答

matplotlib的字符串形式和excel用的是同一種顏色設(shè)置方式,只不過字符串是用16進制寫的。"#c0504d"就是(192,80,77)。

至于[0,1]的實數(shù)模式,是對于上一方式只能用整數(shù)而做的擴展。當(dāng)然,對excel取色器進行優(yōu)化(其實推薦樓主換個別的取色器,至少用畫圖哇)可以把參數(shù)設(shè)置為(192 / 256, 80 / 256, 77 / 256),這樣會方便些。

乞許 回答

nginx不做邏輯相關(guān)的業(yè)務(wù),你的需求直接用nginx無法實現(xiàn)。改用lua吧