• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

질문이요

20.06.15 00:27 작성 조회수 119

2

import requests
from bs4 import BeautifulSoup
req = requests.get(
'https://www.donga.com/news/Entertainment/List?p=1&prod=news&ymd=&m=')
soup = BeautifulSoup(req.text
, 'html.parser')

for i in soup.select("#contents > div.page > a") :

req2 = requests.get(
"http://www.donga.com/news/List/Enter/" + i['href'])
soup2 = BeautifulSoup(req2.text
, 'html.parser')

for i in soup2.find_all("span", class_="tit") :
print(i.text)


C:\Users\karma\PycharmProjects\pychamwebcrawling\venv\Scripts\python.exe "C:/Users/karma/PycharmProjects/pychamwebcrawling/01_web_crawling_naver_test/url 링크 찾아내서 크롤링.py" Process finished with exit code 0

머가 문제인건가요???


답변 4

·

답변을 작성해보세요.

0

파이팅입니다~

0

irunspal님의 프로필

irunspal

2020.06.15

감사합니다.

기초가부족한 상태라

기초를 잘 다져서 따라해보겠습니다

0

코드를 약간 수정했습니다 여기서부터 한번 시작해보실래요?

0

import requests
from bs4 import BeautifulSoup
req = requests.get('https://www.donga.com/news/Entertainment/List?p=1&prod=news&ymd=&m=')
soup = BeautifulSoup(req.text, 'html.parser')

print(soup.select("#content > div.page > a"))

for i in soup.select("#content > div.page > a") :
print("http://www.donga.com/news/List/Enter/" + i['href'])