Skip to content

Instantly share code, notes, and snippets.

@ultrakain
ultrakain / naverdic.py
Created March 2, 2017 14:20
query to naver dictionary
import sys
import requests
from bs4 import BeautifulSoup
def search_naver_dic(query_keyword):
dic_url = """http://endic.naver.com/search.nhn?sLn=kr&dicQuery={0}&x=12&y=12&query={0}&target=endic&ie=utf8&query_utf=&isOnlyViewEE=N
Method=GET"""
r = requests.get(dic_url.format(query_keyword))
soup = BeautifulSoup(r.text, "html.parser")
@ultrakain
ultrakain / daumdic.py
Created March 2, 2017 14:22
query to daum dictionary
import sys
import requests
from bs4 import BeautifulSoup
def search_daum_dic(query_keyword):
dic_url = """http://dic.daum.net/search.do?q={0}"""
r = requests.get(dic_url.format(query_keyword))
soup = BeautifulSoup(r.text, "html.parser")
result_means = soup.find_all(attrs={'class':'list_search'})
@ultrakain
ultrakain / getprice.py
Created March 2, 2017 14:30
find price element
import requests
from bs4 import BeautifulSoup
craw_url = '''http://www.ticketmonster.co.kr/deal/515095746'''
page = requests.get(craw_url)
product_contents = page.text
soup = BeautifulSoup(product_contents)
price_tag = soup.find('strong', {'class':'now_price'})
@ultrakain
ultrakain / dcinside.py
Created March 2, 2017 14:31
get board titles
from lxml import html
import requests
page = requests.get('http://gall.dcinside.com/board/lists/?id=kimnamgil&page=')
dc_content = unicode(page.text).encode('utf-8')
tree = html.fromstring(dc_content)
#This will create a list of buyers:
titles = tree.xpath('//td[@class="t_subject"]/a/text()')
@ultrakain
ultrakain / amazone_pdp.py
Created March 2, 2017 14:55
Get price at amazon pdp
import requests
from bs4 import BeautifulSoup
def get_price():
url = r'''https://www.amazon.com/Xiaomi-10000mAh-External-Portable-Smartphone/dp/B01CU0Z3UE/ref=s9u_simh_gw_i2?_encoding=UTF8&fpl=fresh&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=&pf_rd_r=3SPPSMHRQEVAYS1KWZBD&pf_rd_t=36701&pf_rd_p=1cded295-23b4-40b1-8da6-7c1c9eb81d33&pf_rd_i=desktop'''
res = requests.get(url)
soup = BeautifulSoup(res.text)
price_span = soup.find("span", id="priceblock_ourprice")
print price_span.text
@ultrakain
ultrakain / leopold-need-login.py
Last active March 2, 2017 15:26
query to leopold site
# -*- coding:utf-8 -*-
import requests
from bs4 import BeautifulSoup
def leopold_login(id, password):
# 로그인 정보를 담을 수 있는 객체
s = requests.Session()
""" 로그인을 처리하는 페이지 URL """
@ultrakain
ultrakain / excel-write.py
Last active March 31, 2017 13:27
write excel with openpyxl
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill
wb = Workbook()
dest_filename = 'empty_book.xlsx'
ws1 = wb.active
ws1.title = u"샘플"
ws1['A1'] = '과일종류'
@ultrakain
ultrakain / member.csv
Last active March 3, 2017 01:55
sample csv file
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
소닉 010-1111-2222 "개발자" "팀, 여행"
비랑 010-2222-3333 "아키텍쳐" "팀, 리테일"
DG 010-3333-4444 "개발자" "팀, 정산"
우니 010-4444-5555 "개발자" "팀, 리테일"
올라 010-5555-6666 "개발자" "팀, 리테일"
@ultrakain
ultrakain / csv-read-write.py
Created March 3, 2017 02:06
python csv read write
# -*- coding:utf8 -*-
import csv
# read
with open('eggs.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in spamreader:
print ', '.join(row)
# append
@ultrakain
ultrakain / score.py
Last active April 1, 2017 02:13
python if example
score = input('Input score : ')
score_num = int(score)
if score_num >= 90:
print('A')
elif score_num >= 80 and score_num < 90:
print('B')
elif score_num >= 70 and score_num < 80:
print('C')
elif score_num >= 60 and score_num < 70: