웹 크롤링 파이썬 2

[소스코드]
import urllib.request
import bs4

url = "https://www.naver.com/"html = urllib.request.urlopen(url)

bs_obj = bs4.BeautifulSoup(html, "html.parser")

top_right = bs_obj.find("div", {"class":"area_links"})
first_a = top_right.find("a")
#first_a2 = first_a.textprint(top_right)
print(first_a.text)

top_left_cafe = bs_obj.find("ul", {"class":"an_l"})
top_lef_cafe_a = top_left_cafe.find("span")
#for li in top_left_cafe:#    print(li)lis = top_left_cafe.findAll("li")
#print(lis)
for li in lis:
    a_tag = li.find("a")
    span = a_tag.find("span",{"class":"an_txt"})
    print(span.text)
    #print(li)    #print(a_tag)
#print(top_left_cafe)#print(top_lef_cafe_a.txt)


[결과]

<div class="area_links">
<a class="al_favorite" data-clk="top.mkhome" href="http://help.naver.com/support/alias/contents2/naverhome/naverhome_1.naver">네이버를 시작페이지로<span class="al_ico_link"></span></a>
<span class="al_bar"></span>
<a class="al_jr" data-clk="top.jrnaver" href="http://jr.naver.com"><span class="blind">쥬니어네이버</span><span class="al_ico"></span></a>
<a class="al_happybean" data-clk="top.happybean" href="http://happybean.naver.com/main/SectionMain.nhn"><span class="blind">해피빈</span><span class="al_ico"></span></a>
</div>
네이버를 시작페이지로
메일
카페
블로그
지식인
쇼핑
네이버페이
네이버TV
웹 크롤링 파이썬 2 웹 크롤링 파이썬 2 Reviewed by kukanuc on 2월 18, 2019 Rating: 5

댓글 없음:

Powered by Blogger.