Skip to content

Instantly share code, notes, and snippets.

View ayonliu's full-sized avatar

Lyon Liu ayonliu

View GitHub Profile
@ayonliu
ayonliu / middlewares.py
Created October 27, 2015 03:52 — forked from pkmishra/middlewares.py
Scrapy middlewares for random agent list and proxy server usage.
import os
import random
from scrapy.conf import settings
class RandomUserAgentMiddleware(object):
def process_request(self, request, spider):
ua = random.choice(settings.get('USER_AGENT_LIST'))
if ua:
request.headers.setdefault('User-Agent', ua)
class ProxyMiddleware(object):
@ayonliu
ayonliu / gist:28f0742b500e2669016a
Created October 26, 2015 12:18 — forked from hzopak/gist:9573928
nginx config for scrapyd deployment to implement basic auth protection
# Scrapyd local proxy for basic authentication.
# Don't forget iptables rule.
# iptables -A INPUT -p tcp --destination-port 6800 -s ! 127.0.0.1 -j DROP
server {
listen 6801;
location ~ /\.ht {
deny all;
}