濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > 詳解用python實(shí)現(xiàn)爬取CSDN熱門評(píng)論URL并存入redis

詳解用python實(shí)現(xiàn)爬取CSDN熱門評(píng)論URL并存入redis

熱門標(biāo)簽:原裝電話機(jī)器人 平頂山外呼系統(tǒng)免費(fèi) 江蘇客服外呼系統(tǒng)廠家 清遠(yuǎn)360地圖標(biāo)注方法 400電話申請(qǐng)服務(wù)商選什么 西藏智能外呼系統(tǒng)五星服務(wù) 工廠智能電話機(jī)器人 在哪里辦理400電話號(hào)碼 千陽自動(dòng)外呼系統(tǒng)

一、配置webdriver

下載谷歌瀏覽器驅(qū)動(dòng),并配置好

import time
import random
from PIL import Image
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
if __name__ == '__main__':
  options = webdriver.ChromeOptions()
  options.binary_location = r'C:\Users\hhh\AppData\Local\Google\Chrome\Application\谷歌瀏覽器.exe'
  # driver=webdriver.Chrome(executable_path=r'D:\360Chrome\chromedriver\chromedriver.exe')
  driver = webdriver.Chrome(options=options)
  #以java模塊為例
  driver.get('https://www.csdn.net/nav/java')
  for i in range(1,20):
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
    time.sleep(2)

二、獲取URL

from bs4 import BeautifulSoup
from lxml import etree 
html = etree.HTML(driver.page_source)
# soup = BeautifulSoup(html, 'lxml')
# soup_herf=soup.find_all("#feedlist_id > li:nth-child(1) > div > div > h2 > a")
# soup_herf
title = html.xpath('//*[@id="feedlist_id"]/li/div/div/h2/a/@href')

可以看到,一下爬取了很多,速度非常快

三、寫入Redis

導(dǎo)入redis包后,配置redis端口和redis數(shù)據(jù)庫,用rpush函數(shù)寫入
打開redis

import redis
r_link = redis.Redis(port='6379', host='localhost', decode_responses=True, db=1)
for u in title:
    print("準(zhǔn)備寫入{}".format(u))
    r_link.rpush("csdn_url", u)
    print("{}寫入成功!".format(u))
print('=' * 30, '\n', "共計(jì)寫入url:{}個(gè)".format(len(title)), '\n', '=' * 30)

大功告成!

在Redis Desktop Manager中可以看到,爬取和寫入都是非常的快。


要使用只需用rpop出棧就OK

one_url = r_link.rpop("csdn_url)")
while one_url:
  print("{}被彈出!".format(one_url))

到此這篇關(guān)于詳解用python實(shí)現(xiàn)爬取CSDN熱門評(píng)論URL并存入redis的文章就介紹到這了,更多相關(guān)python爬取URL內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • python 爬取京東指定商品評(píng)論并進(jìn)行情感分析
  • python爬取晉江文學(xué)城小說評(píng)論(情緒分析)
  • 利用Python網(wǎng)絡(luò)爬蟲爬取各大音樂評(píng)論的代碼
  • python 利用百度API進(jìn)行淘寶評(píng)論關(guān)鍵詞提取
  • python 爬取騰訊視頻評(píng)論的實(shí)現(xiàn)步驟
  • python爬取微博評(píng)論的實(shí)例講解
  • python實(shí)現(xiàn)模擬器爬取抖音評(píng)論數(shù)據(jù)的示例代碼
  • 如何基于Python爬取隱秘的角落評(píng)論
  • Python實(shí)現(xiàn)爬取并分析電商評(píng)論
  • python 爬取馬蜂窩景點(diǎn)翻頁文字評(píng)論的實(shí)現(xiàn)
  • 用Python爬取QQ音樂評(píng)論并制成詞云圖的實(shí)例
  • python 爬取華為應(yīng)用市場評(píng)論

標(biāo)簽:日照 隨州 錦州 白城 股票 天水 西安 安慶

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《詳解用python實(shí)現(xiàn)爬取CSDN熱門評(píng)論URL并存入redis》,本文關(guān)鍵詞  詳解,用,python,實(shí)現(xiàn),爬取,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《詳解用python實(shí)現(xiàn)爬取CSDN熱門評(píng)論URL并存入redis》相關(guān)的同類信息!
  • 本頁收集關(guān)于詳解用python實(shí)現(xiàn)爬取CSDN熱門評(píng)論URL并存入redis的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    都江堰市| 广宗县| 四子王旗| 芦溪县| 双桥区| 巴塘县| 瑞丽市| 井研县| 临沭县| 青浦区| 临海市| 久治县| 临泉县| 辽宁省| 云梦县| 西宁市| 兴隆县| 米泉市| 龙南县| 双牌县| 福建省| 隆昌县| 玛多县| 久治县| 九龙坡区| 澄城县| 蒲江县| 巴中市| 吉水县| 万载县| 新乐市| 马公市| 恩施市| 舞阳县| 图片| 永州市| 苏尼特左旗| 新晃| 桃园市| 伊金霍洛旗| 绥阳县|