bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

java爬蟲與python爬蟲對(duì)比哪個(gè)更簡(jiǎn)單

這篇文章將為大家詳細(xì)講解有關(guān)java爬蟲與python爬蟲對(duì)比哪個(gè)更簡(jiǎn)單,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)專注于佛坪企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),成都做商城網(wǎng)站。佛坪網(wǎng)站建設(shè)公司,為佛坪等地區(qū)提供建站服務(wù)。全流程按需開發(fā),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

java爬蟲與python爬蟲的對(duì)比:

python做爬蟲語(yǔ)法更簡(jiǎn)單,代碼更簡(jiǎn)潔。java的語(yǔ)法比python嚴(yán)格,而且代碼也更復(fù)雜

示例如下:

url請(qǐng)求:

java版的代碼如下:

public String call (String url){
            String content = "";
            BufferedReader in = null;
            try{
                URL realUrl = new URL(url);
                URLConnection connection = realUrl.openConnection();
                connection.connect();
                in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"gbk"));
                String line ;
                while ((line = in.readLine()) != null){
                    content += line + "\n";
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            finally{
                try{
                    if (in != null){
                        in.close();
                    }
                }catch(Exception e2){
                    e2.printStackTrace();
                }
            }
            return content;
        }

python版的代碼如下:

# coding=utf-8
import chardet
import urllib2
url = "http://www.baidu.com"
data = (urllib2.urlopen(url)).read()
charset = chardet.detect(data)
code = charset['encoding']
content = str(data).decode(code, 'ignore').encode('utf8')
print content

正則表達(dá)式

java版的代碼如下:

public String call(String content) throws Exception {
            Pattern p = Pattern.compile("content\":\".*?\"");
            Matcher match = p.matcher(content);
            StringBuilder sb = new StringBuilder();
            String tmp;
            while (match.find()){
                tmp = match.group();
                tmp = tmp.replaceAll("\"", "");
                tmp = tmp.replace("content:", "");
                tmp = tmp.replaceAll("<.*>", "");
                sb.append(tmp + "\n");
            }
            String comment = sb.toString();
            return comment;
        }
    }

python的代碼如下:

import repattern = re.compile(正則)
group = pattern.findall(字符串)

關(guān)于java爬蟲與python爬蟲對(duì)比哪個(gè)更簡(jiǎn)單就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

分享名稱:java爬蟲與python爬蟲對(duì)比哪個(gè)更簡(jiǎn)單
URL地址:http://vcdvsql.cn/article48/pdeoep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、ChatGPT、關(guān)鍵詞優(yōu)化、網(wǎng)站導(dǎo)航建站公司虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)