Facebook是用POST去抓canvas/iFrame,
但是nginx處理static file預設不給POST,
workaround如下:
location / {
error_page 405 =200 $uri;
root /var/www/html/yoursite.com;
}
比較好的處理如下:
http://invalidlogic.com/2011/04/12/serving-static-content-via-post-from-nginx/
brew install fish2. 設定檔在: ~/.config/fish/config.fish (自己新增) 顯示git branch,
chsh -s /usr/local/bin/fish4. 以上出現"non-standard shell"錯誤, 到/etc/shells加"/usr/local/bin/fish"
git fetch --all git reset --hard origin/masterref: http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull
from BeautifulSoup import BeautifulSoup改成
from bs4 import BeautifulSoupmethod name也有改,參考。 不過這次遇到的是內容是javascript產生的,如play.google.com,以前可能看一下js的code,學他送http request出去就可抓回來,現在的js越來越複雜,不好搞。
var page = require('webpage').create(), t, address; if (phantom.args.length === 0) { //console.log('Usage: loadspeed.jscommand line執行$ phantomjs my_scrapy.js my_url console.log裡的資料就回跑出來了。 Python裡用commands.getoutput,再json.loads把JSON拆成dict,大改就這樣吧。'); phantom.exit(); } else { address = phantom.args[0]; page.open(address, function (status) { if (status !== 'success') { //console.log('FAIL to load the address'); } else { if (page.injectJs("jquery.min.js")) { //console.log("jQuery loaded..."); } var get_data = page.evaluate(function () { var data = {} data['title'] = $('h1.doc-banner-title').text(); data['content'] = $('#doc-original-text').text(); data['icon'] = $('.doc-banner-icon img').attr('src'); var img_list = [] $('.screenshot-carousel-content-container img').each(function(){ img_list.push($(this).attr('src')) }); data['images'] = img_list return JSON.stringify(data); }); console.log(get_data); phantom.exit(); } }); }
import commands import json out = commands.getoutput(my_cmd) data = json.loads(out)
<input name="animal" type="checkbox" value="lion" /> <input name="animal" type="checkbox" value="tiger" />就要用request.form.getlist('animal')取的list。
<input name="icon[]" type="file" />就要用request.files,是一個werkzeug自定的ImmutableMultiDict。 如果是同一個name的多檔案(input array)
<input name="image[]" type="file" /> <input name="image[]" type="file" />request.files裡有值,但是用for j in request.files:同一個input name只能抓第一個出來,有人說:Flask-WTF的FileField可以解決(沒試過)。後來去看了Werkzeug的原始碼:
class MultiDict ... def iteritems ...學他用
for key, values in dict.iteritems(request.files): for value in values: print key, value就可以了。
sudo pip uninstall PIL
sudo apt-get install libjpeg-dev
sudo pip install PIL
allow_blank=True, blank_text=u'-- please choose --'
Forbidden
You don't have permission to access xxx on this server.
cat = {} # 先初始一個dict
for k, v in foo_list:
cat.setdefault(k, []).append(v)
exec ssh-agent bash