浏览 401 次
锁定老帖子 主题:趣味爬虫之天气预报信息的获取
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2022-01-13
import requests import random # 要访问的目标页面 targetUrl = "http://www.weather.com.cn/" # 要访问的目标HTTPS页面 # targetUrl = "https://www.weather.com.cn/" # 代理服务器(产品官网 www.16yun.cn) proxyHost = "t.16yun.cn" proxyPort = "31111" # 代理验证信息 proxyUser = "username" proxyPass = "password" proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % { "host" : proxyHost, "port" : proxyPort, "user" : proxyUser, "pass" : proxyPass, } # 设置 http和https访问都是用HTTP代理 proxies = { "http" : proxyMeta, "https" : proxyMeta, } # 设置IP切换头 tunnel = random.randint(1,10000) headers = {"Proxy-Tunnel": str(tunnel)} resp = requests.get(targetUrl, proxies=proxies, headers=headers) print resp.status_code print resp.text数据信息获取的部分就是这么简单,对爬虫感兴趣的小伙伴可以实践起来。对代理方面有需求的可以咨询这里https://www.16yun.cn若有收获,就点个赞吧 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |