Introduction to Web Crawler

Web Crawler

おはよう、Royです。

Today Im going to introduce something interesting, Web Crawler.

Web Crawler provide us a easier way to gather information from website(Google is an enormous crawler). And we can easily make our web crawler.

Lets start from the most easy way:
We wanna gather information from a website. We need to open a a webpage, choose what we want, copy and paste. Web crawler does the same thing. Lets see a simple example:

I wanna save some kawaii emotions from http://www.mengma.moe/

#coding=utf-8

import urllib2
import re
from bs4 import BeautifulSoup

kawaii = open('emotions.txt', 'w+')

url = "http://mengma.moe/"

html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)

for emotion in soup.find_all('input', title='鼠标浮动在我上面可以直接Ctrl+C复制噢'):
    moe = emotion.get('value').encode('utf-8')
    kawaii.write(moe + '\n')

kawaii.close()

urllib2, re: Python built-in library
BeatifuleSoup: http://www.crummy.com/software/BeautifulSoup/

The code uses "html = urllib2.urlopen(url).read()" to open the page, then use "moe = emotion.get('value').encode('utf-8')" to pick out what we want, and save it into file.

So by the crawler, you can gather information from millions of pages easily by code.

If you are interested in web crawling, scrapy would be a powerful friend, scrapy is a fast high-level web crawling and screen scraping framework, used to crawl websites and extract structured data from their pages.

Have a good weekend, and next time let's talk more about web crawler.

関西の文系学生が渋谷でエンジニアとして働いてみる。

こんにちは!インターファームにてインターン中の高田です。
今年の2月からインターンをしています!同じインターン浦川くんと一緒に、railsで写真共有サービスを開発中。

ざっと僕のスペックについて
・関西の某国立大学の4年生(来年は5年生に☆)
・学部は経営学部。大学3年まではプログラミングやったことない
・大学3年終了後にインドに行く。ITすげえと感じる(棒読み)
・インド人からインターネットの仕組みと、phpについて学ぶ。ITすげえと感じる(棒)
・エンジニアの社会人「webアプリ作るならphpじゃなくてRubyやっとけ」→Rubyを勉強し始める。
・インターファームであったgit勉強会のシェアをfacebookで見る→「gitって何かわからんけど行ってみよ☆」
・インターファームでインターンをさせていただくことに。写真共有アプリの設計と開発をやる←今ここ

文系の視点から色々書いていきたいと思います。


《今の開発の流れ》
インターン生の二人で新しいWebアプリを作ろうってことでRuby on Rails を勉強しつつ開発しています。
サービスの設計部分が僕にとっては難しいと感じているので、ここを主にインターファームのスーパーエンジニアの方々に聞いています。

あとは、

パーフェクト Ruby on Rails

パーフェクト Ruby on Rails


Ruby on Rails Tutorialrailstutorial.jp

とにらめっこしつつ機能の実装とかをやっています。

Ruby on Railsで最初に学んだこと 〜MVCアーキテクチャ〜》

せっかくなので、railsを学ぶ上で最初に触れたMVCアーキテクチャについて説明したいと思います。
Ruby on Rails を勉強する上でまず理解しないといけないのが、MVCアーキテクチャという概念。

MVCとは、
M(Model):データベースとやりとりを行う部分。
V(View):ユーザーにどんな結果を見せるかを扱う部分。
C(Controller):ユーザーからの信号を変換し、モデルやビューに指示を出す部分。
の3つのことになります。

Railsでは、どうやらこの3つが非常に重要(らしいです。)
まだ勉強不足ですが、この3つの概念を図に表すとこんな感じです。
f:id:techinterfirm:20150318174354p:plain
Ruby on Rails Tutorialより画像参照

つまり、
firefox「近くのいい感じのお店教えて。」
controller 「了解です!モデルくん、お店の情報って確かデータベースの中にあったよね?」
model「はいよー。データベースのここにあったなー。ほれ。」
controller「ありがとうモデルくん!ビューくん、これがお店情報だから、画面に映せる感じに変換してくれない?」
view「わっかりましたー!こんな感じでいいっすか?」
controller「お、いいね!ありがとう。」
controllerfirefoxさん、いい感じのお店の情報はこんな感じです!」
firefox「さっすがMVC三兄弟!頼りになるわ〜。」

って感じでしょうか。
僕が理解している範囲だとこんな感じです!
理解が浅くて薄っぺらい説明になっていまいましたが、これからrailsの開発を進めて
進捗をブログで報告できればと思っています!

Getting Start with Django/PostgreSQL on Heroku

こんにちわ、Royです!

Heroku is a powerful cloud application platform. It provides everything you need to build, run, and scale. Heroku supports Ruby, Node.js, Python, Java, and PHP so you can use the languages you already know to build and deploy apps on Heroku.

Aha, let's start:

  1. Install the heroku-toolbelt, it's very convenient to when you are using Heroku, well, dont install heroku-toolbelt by brew, because by this you wont install foreman at the same time.

  2. Write a useful requirements.txt, that's what make sure that your projects can run well on Heroku server, there are some modules you must add in that file:

     Django (haha, you should have this)
     psycopg2
     dj-database-url==0.3.0
     dj-static==0.0.6
     django-toolbelt==0.0.1
     gunicorn==19.0.0
     static3==0.5.1
     wsgiref==0.1.2
    
  3. for your django settings.

     DATABASES['default'] =  dj_database_url.config()
     # set Database info on Heroku server
     STATIC_ROOT = 'staticfiles'
     STATIC_URL = '/static/'
     STATICFILES_DIRS = (os.path.join(BASE_DIR, '../static'),)
     #set where to store the static files
    

    if you wanna use DEBUG mode in Django, add a config like HEROKU_ENV on Heroku to turn DEBUG on/off at online/offline. Add that like this "heroku set:config HEROKU_ENV=TRUE

  4. After git push heroku master, dont forget to set your database

     heroku run python manage.py syncdb
     heroku run python manage.py migrate(if with south&tastypie)
    
  5. Aha, the last step "heroku open"! see your website welcome page!