• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    selenium和casperjs2種數據抓取方式(進來的朋友請留言,共同探討

    來源:懂視網 責編:小采 時間:2020-11-09 08:32:20
    文檔

    selenium和casperjs2種數據抓取方式(進來的朋友請留言,共同探討

    selenium和casperjs2種數據抓取方式(進來的朋友請留言,共同探討:今天用selenium和casperjs2種對https://class.coursera.org/nlp/lecture網站的ppt、pdf、srt、MP4的下載地址進行數據抓取 1、pythonselenium #!/usr/bin/python# -*- coding: utf-8 -*-from selenium import
    推薦度:
    導讀selenium和casperjs2種數據抓取方式(進來的朋友請留言,共同探討:今天用selenium和casperjs2種對https://class.coursera.org/nlp/lecture網站的ppt、pdf、srt、MP4的下載地址進行數據抓取 1、pythonselenium #!/usr/bin/python# -*- coding: utf-8 -*-from selenium import

    今天用selenium和casperjs2種對https://class.coursera.org/nlp/lecture網站的ppt、pdf、srt、MP4的下載地址進行數據抓取 1、pythonselenium #!/usr/bin/python# -*- coding: utf-8 -*-from selenium import webdriverfrom bs4 import BeautifulSoupimport t

    今天用selenium和casperjs2種對https://class.coursera.org/nlp/lecture網站的ppt、pdf、srt、MP4的下載地址進行數據抓取

    1、python+selenium

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    from selenium import webdriver
    from bs4 import BeautifulSoup
    
    import time
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')
    
    def catchDate(s):
     """頁面數據提取"""
     soup = BeautifulSoup(s)
     z = []
     
     m = soup.findAll("ul",class_="course-item-list-div-list")
     
     for obj in m:
     try:
     print obj.previous_sibling.find('h3').get_text()
     tmp = obj.findAll('li', class_="unviewed")
     for eachli in tmp:
     titleli = eachli.find('a').get_text()
     print ' '+titleli
     allaInEachDiv = eachli.find('div', class_="course-lecture-item-resource").findAll('a')
     for eacha in allaInEachDiv:
     print ' '+eacha['href']
     except Exception, e:
     continue
     if(tmp != ""):
     z.append(tmp)
     return z
    
    starttime = time.time()
    driver = webdriver.PhantomJS(executable_path='C:\phantomjs-1.9.7-windows\phantomjs.exe')
    driver.get("https://class.coursera.org/nlp/lecture")
    html = driver.page_source
    content = catchDate(html)
    endtime = time.time()
    print endtime - starttime
    driver.quit

    2、casperjs
    var casper = require("casper").create({
    	clientScripts: ["jquery-1.7.js"], 
     stepTimeout: 120 * 1000, 
     pageSettings: { 
     loadImages: false 
     }, 
     verbose: true, 
     logLevel: "error" 
    }); 
    var numberOfLinks = 0;
    
    var fs = require('fs');
    var filename = 'content.txt';
    var fullContent = "";
    var startTime = new Date(), endTime;
     
    casper.start("https://class.coursera.org/nlp/lecture", function() {
     numberOfLinks = this.evaluate(function() {
     return __utils__.findAll('.course-item-list-div-list').length;
     });
     this.echo(numberOfLinks + " items found");
    });
    getStartTime = function(){
    	this.echo(startTime);
    	this.then(getcontent);
    };
    getcontent = function() {
     fullContent = this.evaluate(function() {
     var content = "";
     jQuery('.course-item-list-div-list').each(function() {
    	var btitle = $(this).prev().find("h3").text();
    	content += btitle + '\r\n';
    	$(this).find("li").each(function(){
    	var stitle = $(this).find("a").first().text();
    	content += stitle + '\r';
    	$(this).find("div a").each(function(){
    	content += $(this).attr("href")+'\r';
    	});
    	content += '\r\n';
    	});
    	content += '\r\n\r\n';
     });
     return content;
     });
    	this.then(writefile);
    };
    
    writefile = function() {
     this.echo('writing to ' + filename);
     fs.write(filename, fullContent, 'w');
    	this.then(getEndTime);
    };
    getEndTime = function(){
    	endTime = new Date();
    }
    casper.then(getStartTime);
    casper.then(function exitSystem() {
    	this.echo(new Date() - startTime);
     casper.exit(); 
    }); 
    
    casper.run();
    

    因為不熟練,感覺寫的不太好,求大神對方法進行指導!!!


    參考:

    https://gist.github.com/imjared/5201405

    http://casperjs.readthedocs.org/en/latest/modules/casper.html#evaluate

    http://blog.csdn.net/u012577500/article/details/18185399

    http://stackoverflow.com/questions/14894311/casperjs-windows-installation-how-is-it-done-the-correct-way-please

    http://blog.csdn.net/sagomilk/article/details/20800543

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    selenium和casperjs2種數據抓取方式(進來的朋友請留言,共同探討

    selenium和casperjs2種數據抓取方式(進來的朋友請留言,共同探討:今天用selenium和casperjs2種對https://class.coursera.org/nlp/lecture網站的ppt、pdf、srt、MP4的下載地址進行數據抓取 1、pythonselenium #!/usr/bin/python# -*- coding: utf-8 -*-from selenium import
    推薦度:
    標簽: 數據 留言 的朋友
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 99久久精品国产一区二区| 日韩精品无码永久免费网站| 国产乱子伦精品无码专区| 精品久久8x国产免费观看| 精品人妻少妇一区二区| 9久久9久久精品| 在线亚洲精品自拍| 久久精品无码一区二区日韩AV | 欧美日韩综合精品| 拍国产乱人伦偷精品视频| 国产精品久久久福利| 一本久久a久久精品vr综合| 精品久久久无码中文字幕| 日本精品一区二区三区在线观看| 日韩精品一区二区亚洲AV观看| 亚洲精品偷拍视频免费观看| 精品国产成人在线| 99精品影院| 91精品一区二区综合在线| 国内精品久久国产大陆| 99精品热这里只有精品 | 亚洲精品高清国产一久久| 国产精品精品自在线拍| 无码人妻精品一区二区| 在线观看91精品国产网站| 亚洲AV永久无码精品一区二区| 精品99又大又爽又硬少妇毛片 | 亚洲精品国产高清嫩草影院 | 精品久久久无码中文字幕| 国产精品热久久无码av| 99精品福利国产在线| 伊人久久大香线蕉精品| 日韩精品在线看| 欧美精品888| 国产精品v欧美精品v日韩精品| 国产精品美女久久久久| 国产精品免费看久久久| 国产亚洲综合成人91精品| 国产精品莉莉欧美自在线线| 国产精品免费网站| 久久精品免费一区二区三区|