yhahn02
Reviews Written
1
Average Rating
5.0
Posts
Q&A
๋ค์ด๋ฒ ๋ด์ค๋ณธ๋ฌธ ๊ฐ์ง๊ณ ์ค๊ธฐ๋ ๋๊ณ ์ฐ์๋ด์ค๋ ๋๋๋ฐ ์คํฌ์ธ ๋ด๋ง ์๋๋ค์?
import requests from bs4 import BeautifulSoup import time import pyautogui keyword = pyautogui.prompt("๊ฒ์์ด๋ฅผ ์ ๋ ฅ ํ์ธ์") response = requests.get(f"https://search.naver.com/search.naver?sm=tab_sug.top&where=news&query={keyword}") html = response.text soup = BeautifulSoup(html,'html.parser') articles = soup.select("div.info_group") for article in articles: links = article.select("a.info") if len(links) >= 2: url = links[1].attrs["href"] response = requests.get(url,headers={'User-agent':'Mozila/5.0'}) html = response.text soup = BeautifulSoup(html,'html.parser') # ๋ง์ฝ ์ฐ์ ๋ด์ค๋ผ๋ฉด if "entertain" in response.url: title = soup.select_one(".end_tit") content = soup.select_one ("#articeBody") elif "sports" in response.url: title = soup.select_one("h4.title") content = soup.select_one ("#newsEndContents") # ๋ณธ๋ฌธ ๋ด์ฉ์์ ๋ถํ์ํ div์ญ์ divs = content.select("div") for div in divs: div.decompose() paragraphs = content.select("p") for p in paragraphs: p.decompose() else: title = soup.select_one("#artcleTitle") content = soup.select_one("#areicleBodyContents") print("============๋งํฌ=========\n", url) print("============์ ๋ชฉ=========\n", title.text.strip()) print("============๋ณธ๋ฌธ=========\n", content.text.strip()) time.sleep(0.3) AttributeError: 'NoneType' object has no attribute 'text'(base) tonyahn@Tonyui-MacBookPro vscode % /Users/tonyahn/anaconda3/bin/python /Users/tonyahn/Desktop/my_tony/vscode/Capter04/05.๊ฒ์์ด๋ณ๊ฒฝํ๊ธฐ2023-09-20 15:55:35.653 python[10820:73580] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit============๋งํฌ========= https://n.news.naver.com/mnews/article/277/0005312599?sid=102Traceback (most recent call last): File "/Users/tonyahn/Desktop/my_tony/vscode/Capter04/05.๊ฒ์์ด๋ณ๊ฒฝํ๊ธฐ", line 38, in print("============์ ๋ชฉ=========\n", title.text.strip()) ^^^^^^^^^^AttributeError: 'NoneType' object has no attribute 'text'(base) tonyahn@Tonyui-MacBookPro vscode % /Users/tonyahn/anaconda3/bin/python /Users/tonyahn/Desktop/my_tony/vscode/Capter04/05.๊ฒ์์ด๋ณ๊ฒฝํ๊ธฐ2023-09-20 15:57:04.370 python[10846:74715] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit============๋งํฌ========= https://n.news.naver.com/mnews/article/008/0004940773?sid=101Traceback (most recent call last): File "/Users/tonyahn/Desktop/my_tony/vscode/Capter04/05.๊ฒ์์ด๋ณ๊ฒฝํ๊ธฐ", line 38, in print("============์ ๋ชฉ=========\n", title.text.strip()) ^^^^^^^^^^AttributeError: 'NoneType' object has no attribute 'text'(base) tonyahn@Tonyui-MacBookPro vscode % ์ง๋ฌธ : ๊ฒ์์ด๋ณ๊ฒฝํ๊ธฐ ํ ์ด๋ฐ ํ์์ด ๋ฐ์ ํฉ๋๋ค.
- 0
- 2
- 563
Q&A
๋ค์ด๋ฒ ์ฃผ์ ํฌ๋กค๋ง (1) ์ง๋ฌธ๋๋ฆฝ๋๋ค.
์ ๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐํ ํฉ๋๋ค. ๋ค์ด๋ฒ ์ฃผ์ ํฌ๋กค๋ง (1) ์ง๋ฌธ๋๋ฆฝ๋๋ค.bArgument 'which' was left unspecified. Choosing first table. ๋ผ๊ณ ์๋ฌ๊ฐ ๋์ค๋ฉด ์ด๋กํด์ผ ํ๋์? library(httr)library(rvest)library(htmltab)library(XML)i final_data for(i in 1:10){ url https://finance.naver.com/item/sise_day.nhn?code=005930&page=",i) b b final_data cat("\n",i)}
- 0
- 3
- 340




