2016년 12월 11일 일요일

도지사 안희정

사람한테 끌리기는 오랜만이다.
확실한건 철학이 있는 사람이다. 정치권에 우글거리는 시정잡배같은 사람이 아니다.
그리고 명예롭고 크게 보는 사람이다.
이분을 위해 내가 할수 있는 일이있을까?
찾고싶다. 조금이라도 도움을 보태드리고 싶다.
왜 이제야 이분에 대해 찾아보게 되었을까?
이제 준비가 되셨나보다.


2016년 12월 9일 금요일

대통령 박근혜

무엇이 잘못되었을까.
자신을 직시하지 못하는 사람의 비극이다.
한 나라의 비극이다.
그릇된 생각은 하지 마시길.
사람들이 웃고있어. 흥에겨워 하고있어. 무엇이 그리 즐겁기에.
정세균의원의 메시지.. 새겨들어야지
헛똑똑이들의 세상

2016년 12월 1일 목요일

[Python] 웹사이트 읽기

hello python!!



#1. Default
from urllib.request import urlopen
html = urlopen("http://naver.com")
print(html.read())



#2. Use BeautifulSoup
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://naver.com")
bsObj = BeautifulSoup(html.read(), "html.parser")
print(bsObj.h1)



#3. Set user_agent & 404회피
from urllib.request import Request, urlopen, HTTPError
from bs4 import BeautifulSoup
## 404 에러 회피
contents = None
try:
    url = "https://ko.wikipedia.org"
    user_agent = "Mozilla/5.0..."
    request = Request(url)
    request.add_header('User-Agent', user_agent)
    contents = urlopen(request).read()
except HTTPError as e:
    contents = e.fp.read()
## href 만 추출
bsObj = BeautifulSoup(contents, "html.parser")
for link in bsObj.findAll("a"):
    if 'href' in link.attrs:
        print(link.attrs['href'])