2024년 4월 8일 월요일

2024년 3월 28일 목요일

파이썬에서 BeautifulSoup을 사용한 네이버 블로그 크롤링 코드입니다.

 자주 수정이 됩니다. ㅎㅎ 3월초에 수정을 했었는데 다시 수정을 했습니다. 


import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook

search_keyword='맥북에어'

url = f'https://search.naver.com/search.naver?where=view&sm=tab_jum&query={search_keyword}'

response = requests.get(url)

#<a href="https://blog.naver.com/pareko" class="sub_txt sub_name" target="_blank" onclick="return goOtherCR(this, 'a=rvw*b.writer&amp;r=2&amp;i=90000003_0000000000000033ECA5C9EE&amp;u='+urlencode(this.href))">순돌아범</a>

soup = BeautifulSoup(response.text, 'html.parser')

# create a new Excel workbook and select the active sheet\
wb = Workbook()
ws = wb.active

# write the column names to the first row of the sheet
ws.append(["블로그명", "블로그주소", "글 제목", "포스팅 날짜"])

for page in range(1, 301):
url = f'https://search.naver.com/search.naver?where=view&sm=tab_jum&query={search_keyword}&start={page * 10 - 9}'

#제목
# <a nocr="1" href="https://blog.naver.com/meen703/223388020128" class="QS0gep6K3wmBGxMdfuA3 fds-comps-right-image-text-title" target="_blank" data-cb-target="'SYS-0000000035525141.90000003_000000000000003402F6ADA0'" data-cb-trigger="true"><span class="WNE6DfqawXbjKLCLcd4a"><mark>맥북 에어</mark> M2 13인치 지금 사도 괜찮을까</span></a>
#<span class="WNE6DfqawXbjKLCLcd4a">내돈내산 애플 <mark>맥북에어</mark> M2 [교육할인] 3</span>
#블로그주소
#<a nocr="1" href="https://blog.naver.com/meen703" class="QS0gep6K3wmBGxMdfuA3 fds-info-inner-text" target="_blank"><span class="WNE6DfqawXbjKLCLcd4a">최동구의 알고 싶은 IT 정보</span></a>
#날짜
#<span class="fds-info-sub-inner-text WNE6DfqawXbjKLCLcd4a">4일 전</span>
posts = soup.find_all('div', {'class':'fds-ugc-block-mod-list grY7ARzqEvD6JYNGqTAD'})
for post in posts:
try:
blog_address_elem = post.find("a",
attrs={"class":"QS0gep6K3wmBGxMdfuA3 fds-info-inner-text"})
blog_address = blog_address_elem["href"]
blog_address_title_elem = post.find("a",
attrs={"class":"QS0gep6K3wmBGxMdfuA3 fds-info-inner-text"})
blog_address_title = blog_address_title_elem.text
except TypeError:
blog_address = ""
blog_address_title = ""

post_date_elem = post.find('span', {'class':'fds-info-sub-inner-text WNE6DfqawXbjKLCLcd4a'})
post_date = post_date_elem.text if post_date_elem else ""
post_title_elem = post.find('a',
{'class':'QS0gep6K3wmBGxMdfuA3 fds-comps-right-image-text-title'})
post_title = post_title_elem.text if post_title_elem else ""

print(blog_address)
print(blog_address_title)
print(post_title)
print(post_date)

ws.append([blog_address, blog_address_title, post_title, post_date])

#path = 'c:\\work\\'
#file_path = f'{path}{search_keyword}_blog_data.xlsx'
file_path = f'{search_keyword}_blog_data.xlsx'
wb.save(file_path)

2024년 1월 18일 목요일

스텐포드 대학의 알로하 프로젝트입니다. AI와 로보틱스가 지배하는 세상이 될 수 있습니다.

소프트웨어가 세상을 집어삼키고 있습니다. ㅎㅎ 


세상의 변화 속도가 너무 빠르네요. 이미테이션 러닝이라는 새로운 단어를 배우고 갑니다.  


https://www.youtube.com/watch?v=BeWtXQqy-eo

2024년 1월 2일 화요일

 2023년 8월에 원고를 넘기고 나서 수정된 부분들이 있습니다. ㅎㅎ 

그래서 오늘 GitHub에 코드를 다시 올리고 수정을 했습니다. 


9장에 네이버 크롤링 코드가 수정되었습니다. 네이버는 주기적으로 변경이 됩니다. 


11장 pandasAI와 관련된 내용들이 수정되었습니다. streamlit관련해서도 변경된 내용들이 있습니다. 


=====================================================

*PandasAI설치와 관련된 부분입니다. 

(버전 문제가 있기 때문에 기존 pandas는 제거하고 설치합니다. pandas 최신 버전에 

충돌 문제가 생기기 때문에 판다스를 제거하고 pandasAI를 설치하면 pandas 1.5 버전이 같이 설치됩니다.) 

pip uninstall pandas 

pip install pandasAI 


*OpenAI와 관련된 키는 아래의 주소에서 생성하면 됩니다. 

https://platform.openai.com/account/api-keys



*Streamlit에서 에러가 발생하면 아래와 같이 duckdb버전을 추가로 셋팅합니다. (IOException이 발생하는 경우 pandasAI가 사용하는 버전을 추가로 설치해야 합니다. 아래와 같이 duckdb 버전을 명시해서 설치합니다. )

pip install duckdb==0.8.1


깃허브에 전체 수정된 코드를 올려두었습니다. ^^ 

https://github.com/papasmf1/ChatGPTPython

제 책이 IT프로그래밍 언어 분야에서 Top100에서 41등까지 올라갔습니다. ㅎㅎ

 종이책이 출판된 것이 5번째입니다. ㅎㅎ 

최근의 트렌드와 잘 맞아서 "챗GPT를 활용한 파이썬 프로그래밍"책이 프로그래밍 언어 분야Top100에서 41등까지 올라갔습니다. 


어제 출판사에서 연락이 왔는데 바로 재판에 들어가자고 해서 다시 원고 작업을 해야 할 것 같습니다. 수강생분들과 독자분들에게 감사 드립니다. ^^ 








요즘 많이 들리는 RAG에 대한 멋진 정리가 있어서 공유합니다. ㅎㅎ

 작년에는 ChatGPT가 크게 유행을 했는데 올해는 Gen AI, LLM, 랭체인등이 유행하고 있습니다. ㅎㅎ  RAG라는 단어도 상당히 많이 들리고 있습니다. 멋진 정리의 링크입니다.  https://brunch.co.kr/@ywkim36/146?...