1. 程式人生 > >學習爬蟲的day03 (通過代理去爬去數據)

學習爬蟲的day03 (通過代理去爬去數據)

可能 log time div 設置 utf 3.5 模擬 zha

代理的IP通過去網上找
#
-*- coding: utf-8 -*- import re import _thread from time import sleep, ctime from urllib.request import urlopen from urllib.request import Request from urllib.request import ProxyHandler from urllib.request import build_opener from lxml import etree url = "http://sou.zhaopin.com/jobs/searchresult.ashx?jl=%%E5%%8C%%97%%E4%%BA%%AC&kw=java&sm=0&p=%i
"%(1) #設置代理ip proxy = {http:1.60.114.151:6673}# 這裏的HTTPS 後寫啥都可以訪問,可能是還用自己的ip去訪問 proxy_support = ProxyHandler(proxy) opener = build_opener(proxy_support) #設置訪問http協議頭,模擬瀏覽器 opener.addheaders = [(User-agent, Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6)] r = opener.open(url) html
= r.read().decode(utf-8) print(html)

學習爬蟲的day03 (通過代理去爬去數據)