웹 크롤링 파이썬 4

[소스코드]

import requests
from bs4 import BeautifulSoup

#url = "https://bp.eosgo.io/"url = "https://bp.eosgo.io/listing/eos-land/"
def get_bp_info(url):
    result = requests.get(url =url)
    bs_obj = BeautifulSoup(result.content, "html.parser")

    #print(bs_obj)    #lf_items = bs_obj.findAll("div",{"class": "lf-item"})
    profile_name = bs_obj.find("div",{"class": "profile-name"})
    h1_bp_name = profile_name.find("h1")
    bp_name = h1_bp_name.text

    #print(profile_name)    #print(h1_bp_name.text)
    cover_buttons = bs_obj.find("div",{"class" : "cover-buttons"})
    #print(cover_buttons)
    button_label = cover_buttons.find("span")
    location = button_label.text
    #print(button_label.text)
    lis = cover_buttons.findAll("li")
    #print(lis)
    li_tag = lis[1]
    #print(li_tag)
    a_tag = li_tag.find("a")
    link = a_tag['href']
    print(a_tag['href'])

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

    return dictionary1

dic_result = get_bp_info(url)

print(dic_result)

#print(lf_items)
#hrefs = [div.find("a")['href'] for div in lf_items]
#print(hrefs)
#print(len(hrefs))
#print(hrefs[0:5])#print(len(hrefs[0:5]))

[실행 결과]

http://www.eosland.ca/
{'name': 'EOS Land', 'location': 'Vancouver', 'link': 'http://www.eosland.ca/'}


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

댓글 없음:

Powered by Blogger.