프롬프트 링크 부터 공유 드립니다!
https://chat.openai.com/share/a23779da-0f07-489a-a7ee-90f7709c0acf
https://chat.openai.com/share/6a555996-994d-48c6-9c7a-93bfbcc872db
https://chat.openai.com/share/d5dba175-bf60-4b47-a3b1-d50cfff0d33e
https://chat.openai.com/share/e296e0df-36a5-4d94-b16d-785eed328613
https://chat.openai.com/share/5cb3d591-8f77-470c-bdbb-90f20a0cf328
test1.py
import requests
from bs4 import BeautifulSoup
def get_text_from_url(url):
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
# HTML에서 모든 태그 제거하고 텍스트만 가져옴
text = soup.get_text(separator=' ', strip=True)
return text
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return None
def save_text_to_file(text, filename='output.txt'):
try:
with open(filename, 'w', encoding='utf-8') as file:
file.write(text)
print(f"Text saved to {filename}")
except IOError as e:
print(f"Error saving text to file: {e}")
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
# 위에서 작성한 함수를 사용하여 텍스트를 가져옴
url = 'https://namu.wiki/w/ChatGPT'
text = get_text_from_url(url)
if text:
save_text_to_file(text, filename='output.txt')
findtext = find_between(text, '2. 특징 및 인터페이스 [편집]', '3. 등장 배경 [편집]')
save_text_to_file(findtext, filename='특징및인터페이스.txt')
test2.py
import requests
from bs4 import BeautifulSoup
def get_text_from_url(url):
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
# HTML에서 모든 태그 제거하고 텍스트만 가져옴
## text = soup.get_text(separator=' ', strip=True)
return (str(soup))
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return None
def save_text_to_file(text, filename='output.txt'):
try:
with open(filename, 'w', encoding='utf-8') as file:
file.write(text)
print(f"Text saved to {filename}")
except IOError as e:
print(f"Error saving text to file: {e}")
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
# 이번엔 위에 html 태그 제거를 빼고 텍스트 가져옴
url = 'https://www.youtube.com/@gpters/videos'
text = get_text_from_url(url)
if text:
save_text_to_file(text, filename='output2.txt')
titlelist = text.split('"title":{"runs":[{"text":') # split : 문자열을 분할하여 문자가 포함된 부분 문자열의 리스트를 줍니다
# 말 그대로 문자열을 짤라서 나눠주는 기능입니다
print (titlelist)
youtubetitle = ''
for t in range(0, len(titlelist)):
youtubetitle = youtubetitle + find_between(titlelist[t], '"', '"') + '\n' # \n 은 엔터 (다음줄) 의미
save_text_to_file(youtubetitle, filename='output3.txt')