"맥북프로" 로 검색한 목록을 뷰티풀수프로 꺼내 보겠다.
글목록을 가져올때 현재 페이지와 글 갯수를 지정할 수 있더라... 물론 50개 이상은 불가능하다.
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import re
page = 1
listPerPage = 50
html = requests.get("https://cafe.naver.com/ArticleSearchList.nhn?search.clubid=10050146&search.media=0&search.searchdate=all&search.exact=&search.include=&userDisplay="+str(listPerPage)+"&search.exclude=&search.option=0&search.sortBy=date&search.searchBy=0&search.searchBlockYn=0&search.includeAll=&search.query=%B8%C6%BA%CF%C7%C1%B7%CE&search.viewtype=title&search.page="+str(page))
soup = BeautifulSoup(html.content.decode("euc-kr", "replace"), "html.parser")
junggo = soup.find("div", id="content-area").find_all("div", id="main-area")[0].find_all("div", class_="article-board")[1]
junggo = junggo.find("tbody").find_all("tr")
for item in junggo :
title = item.find("td", class_="td_article")
if title != None :
str = title.find("div", class_="board-list").find("a", class_="article")
if str.find(text=re.compile("2020")) :
print(" ".join(str.stripped_strings))
[판매]애플 2020 맥북프로 13 MXK62KH/A 램CTO 제품 팜
[판매]2020 맥북프로 13인치 고급형 MWP72KH/A i5-10세대.16G.512G
[앱상품][판매완료][2020 맥북프로 16인치 [고급형] 풀박스/1TB/스그][2,500,000원]
[앱상품][2020 맥북프로 13 고급형 MWP52KH/A 팝니다][1,600,000원]
글 갯수를 50개로 하고 텍스트에 2020을 포함하는 목록만 취득하였다. 이렇게 하면 맥북프로 2020 판매글을 찾을 확률이 높아진다.
끝