편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2020.02.20

    네이버 기사 크롤링 검색어 복수 입력


    속보로 검색한 뉴스 검색 결과와 1보로 검색한 뉴스 검색 결과를 모두 출력하도록 하고 싶은데 어떻게 수정해야 하나요??

    아래의 방법으로 사용하고있는데 지저분해 보여서요..

    빠르고 친절한 답변을 주신 이루노님께 감사하지만 가능하면 큰 틀의 수정 없이 search_word 부분만 수정해서 사용하는 방법이 궁금합니다!!

    import requests
    from bs4 import BeautifulSoup
    
    search_word = '속보'
    url = f'https://search.naver.com/search.naver?where=news&query= 
    {search_word}&sm=tab_srt&sort=1'
    
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'html.parser')
    news_titles = soup.select('.news .type01 li dt a[title]')
    
    print()
    for title in news_titles:
        print(title['title'])
    
    
    search_word = '1보'
    url = f'https://search.naver.com/search.naver?where=news&query= 
    {search_word}&sm=tab_srt&sort=1'
    
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'html.parser')
    news_titles = soup.select('.news .type01 li dt a[title]')
    
    print()
    for title in news_titles:
        print(title['title'])
    
  • 프로필 ᅟᅟᅟᅟ님의 편집
    날짜2020.02.17

    크롤링 검색어 복수 입력


    속보로 검색한 뉴스 검색 결과와 1보로 검색한 뉴스 검색 결과를 모두 출력하도록 하고 싶은데 어떻게 수정해야 하나요??

    아래의 방법으로 사용하고있는데 지저분해 보여서요..

    빠르고 친절한 답변을 주신 이루노님께 감사하지만 가능하면 큰 틀의 수정 없이 search_word 부분만 수정해서 사용하는 방법이 궁금합니다!!

    import requests
    from bs4 import BeautifulSoup
    
    search_word = '속보'
    url = f'https://search.naver.com/search.naver?where=news&query= 
    {search_word}&sm=tab_srt&sort=1'
    
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'html.parser')
    news_titles = soup.select('.news .type01 li dt a[title]')
    
    print()
    for title in news_titles:
        print(title['title'])
    
    
    search_word = '1보'
    url = f'https://search.naver.com/search.naver?where=news&query= 
    {search_word}&sm=tab_srt&sort=1'
    
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'html.parser')
    news_titles = soup.select('.news .type01 li dt a[title]')
    
    print()
    for title in news_titles:
        print(title['title'])