beautiful soup 웹크롤링 제ㅔ발 도와주세요..
-
게시물 수정 , 삭제는 로그인 필요
도서 사이트에서 도서명, 저자명, 이미지 링크를 차례대로 추출해서 엑셀 파일로 만들려고하는데요ㅠ 도서명이랑 저자명까지는 이렇게 해서 성공했어요
url = "https://www.yes24.com/24/category/bestseller?CategoryNumber=001001002006&sumgb=03" #생명과학
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')
book_list = []
book_info_list = soup.select('td.goodsTxtInfo')
for book_info in book_info_list:
book_name = book_info.select_one('p > a')
author_name = book_info.select_one('div > a')
if book_name and author_name:
book_text = book_name.text.strip()
author_text = author_name.text.strip()
if book_text and author_text:
book_list.append({'도서명': book_text, '저자': author_text})
df = pd.DataFrame(book_list)
df.to_excel('book_list_생명과학ver.xlsx', index=False, header=True)
그리고나서 도서 이미지 링크 추출하려고
from bs4 import BeautifulSoup
import urllib.request
import pandas as pd
url = "https://www.yes24.com/24/category/bestseller?CategoryNumber=001001002006&sumgb=03" # 생명과학
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')
book_list = []
book_info_list = soup.select('td.goodsTxtInfo, div.goods_img > a > img')
for book_info in book_info_list:
book_name = book_info.select_one('p > a')
author_name = book_info.select_one('div > a')
book_image = book_info.select_one('div.goods_img > a > img[src]')
if book_name and author_name and book_image:
book_text = book_name.text.strip()
author_text = author_name.text.strip()
image_url = book_image.get('src')
book_list.append({'도서명': book_text, '저자': author_text, '이미지 URL': image_url}) # 이미지 URL 추가
df = pd.DataFrame(book_list)
df.to_excel('book_list_생명과학ver.xlsx', index=False, header=True)
코드를 이렇게 수정하니까 엑셀 파일안에 아무것도 안 떠요... 도대체 뭐가 잘못된걸까요ㅠㅠㅠㅠㅠㅠ제발도와주세요ㅛㅠㅠㅠㅠㅠㅠㅠ 지피티가 수정해주는대로 해봤는데도 엑셀 파일안에 아무것도 안 떠요..ㅠㅠㅠㅠ 바로 채택해드릴게요 도와주세요 ㅠ.ㅠ
**참고로 이건 도서 사이트 html입니다.. 오른쪽코드가 1번 책이랑 관련된거예요 <tr>이 책 개수만큼 있어요
#beautiful soup #beautiful soup 사용법 #beautifulsoup 설치 #beautiful soup documentation #beautiful soup find_all #beautiful soup select #beautifulsoup4 #beautiful soup selenium #beautiful soup xpath #beautiful soup get text