웹 크롤링 파이썬 5

[소스코드]

import requests
from bs4 import BeautifulSoup



def get_bp_info(url):

    result = requests.get(url =url)
    bs_obj = BeautifulSoup(result.content, "html.parser")

    lf_items = bs_obj.findAll("div",{"class":"lf-item"})

    hrefs = [div.find("a")['href'] for div in lf_items]

    #print(hrefs[0:5])    #print(len(hrefs[0:5]))
    profile_name = bs_obj.find("div", {"class":"profile-name"})
    h1_bp_name = profile_name.find("h1")
    bp_name = h1_bp_name.text

    cover_buttons = bs_obj.find("div", {"class":"cover-buttons"})

    button_label = cover_buttons.find("span", {"class":"button-label"})
    location = button_label.text

    lis = cover_buttons.findAll("li")
    li_tag = lis[1]

    a_tag = li_tag.find("a")
    link = a_tag['href']

    dictionary1 = {}
    dictionary1['name'] = bp_name
    dictionary1['location'] = location
    dictionary1['link'] = link

    return dictionary1

url = "https://bp.eosgo.io/"
result = requests.get(url =url)
bs_obj = BeautifulSoup(result.content, "html.parser")

lf_items = bs_obj.findAll("div", {"class":"lf-item"})

hrefs = [div.find("a")['href'] for div in lf_items]

#print(hrefs)
for number in range(0,5):#len(hrefs):    dic_result = get_bp_info(hrefs[number])
    print(dic_result)






[실행결과]
{'name': 'EOS Dusseldorf', 'location': 'Düsseldorf', 'link': 'https://www.eosdusseldorf.de'}
{'name': 'EOS IMPERA', 'location': 'Roma', 'link': 'https://eosimpera.io'}
{'name': 'GEOS', 'location': 'Singapore', 'link': 'https://www.geos.one'}
{'name': 'Bitcoin God', 'location': 'California', 'link': 'https://eos.bitcoingod.org'}
{'name': 'BlockCC', 'location': 'HongKong', 'link': 'https://eos.block.cc/'}


해당 url의 정보가 달라지면 실행결과의 내용이 약간 달라질 수 있음.
웹 크롤링 파이썬 5 웹 크롤링 파이썬 5 Reviewed by kukanuc on 2월 18, 2019 Rating: 5

댓글 없음:

Powered by Blogger.