1. 웹드라이버를 구성하세요
구글 크롬 드라이버를 다운로드해서 구성하세요
import timeimport randomfrom PIL import Imagefrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECif __name__ == '__main__':options = webdriver.ChromeOptions()options.binary_location = r'C:UsershhhAppDataLocalGoogleChromeApplication谷歌浏览器.exe'# driver=webdriver.Chrome(executable_path=r'D:360Chromechromedriverchromedriver.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)
2. URL을 받아보세요
from bs4 import BeautifulSoupfrom 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_herftitle = html.xpath('//*[@id="feedlist_id"]/li/div/div/h2/a/@href')
한 번에 많은 내용이 크롤링되고 속도도 엄청 빠른 걸 볼 수 있어요
3. Redis에 쓰기
redis 패키지를 가져온 후 ,redis 포트 및 redis 데이터베이스 구성,rpush 함수를 사용하여 쓰기
Redis 열기
import redis r_link = redis.Redis(port='6379', host='localhost', decode_responses=True, db=1)for u in title:print("准备写入{}".format(u))r_link.rpush("csdn_url", u)print("{}写入成功!".format(u))print('=' * 30, 'n', "共计写入url:{}个".format(len(title)), 'n', '=' * 30)
완료되었습니다!
Redis Desktop Manager에서 크롤링 및 쓰기 속도가 매우 빠른 것을 확인할 수 있습니다.
사용하시려면 rpop으로 튀어나오시면 됩니다
one_url = r_link.rpop("csdn_url)")while one_url:print("{}被弹出!".format(one_url))
위 내용은 Python을 사용하여 CSDN 인기 댓글 URL을 크롤링하고 이를 Redis에 저장하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

redisoutperformstraditionaldatabasesinspeedforread/writeoperationsduetoitsin-memorynature, whiletraditionaldatabasesexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexceleclexquer

useredisinsteadofatraditionaldatabasewhenyorapplicationrequiresspeedandreal-timedataprocessing, suchasforcaching, sessionmanagement, orreal-timeanalytics.rediesxcelsin : 1) Caching, Retoadon-PrimaryDatabases; 2) 세션 관리, 단순화 datahandlon

Redis는 고성능과 유연성으로 인해 SQL 데이터베이스를 뛰어 넘습니다. 1) Redis는 메모리 스토리지를 통해 매우 빠른 읽기 및 쓰기 속도를 달성합니다. 2) 복잡한 데이터 처리에 적합한 목록 및 컬렉션과 같은 다양한 데이터 구조를 지원합니다. 3) 단일 스레드 모델은 개발을 단순화하지만 높은 동시성은 병목 현상이 될 수 있습니다.

Redis는 동시성이 높은 기존 데이터베이스보다 우수하고 대기 시간 시나리오가 낮지 만 복잡한 쿼리 및 트랜잭션 처리에는 적합하지 않습니다. 1.Redis는 메모리 저장, 빠른 읽기 및 쓰기 속도, 높은 동시성 및 낮은 대기 시간 요구 사항에 적합합니다. 2. 전통적인 데이터베이스는 디스크를 기반으로하며 복잡한 쿼리 및 트랜잭션 처리를 지원하며 데이터 일관성과 지속성이 강합니다. 3. Redis는 기존 데이터베이스의 보충 또는 대체물로 적합하지만 특정 비즈니스 요구에 따라 선택해야합니다.

redisisahigh-performancein-memorydatrscructurestorestorethexcelscelsspeedandversitility

Redis는 주로 데이터베이스이지만 단순한 데이터베이스 이상입니다. 1. 데이터베이스로서 Redis는 지속성을 지원하고 고성능 요구에 적합합니다. 2. 캐시로서 Redis는 응용 프로그램 응답 속도를 향상시킵니다. 3. 메시지 중개인으로서 Redis는 실시간 커뮤니케이션에 적합한 Publish-Subscribe 모드를 지원합니다.

redisiSamultifacetedToolthatservesAsadatabase, Server 및 more.ItfunctionsAnin-memoryDatrastRuctureStore, SupportSvariousDatastructures, andCanbeusedAsacache, MessageBroker, SessionStorage, 및 FordiptributedLocking을 지원합니다.

redisisanopen-source, in-memorydatructurestorestoreusedasadatabase, cache 및 messagebroker, excell


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.