代理IP,模拟登陆,request.get设置cookie

import random

import re
import requests

#设置请求头
import time

headers = {
    'Host': 'https://blog.csdn.net/weixin_42141853',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
    'Accept-Encoding': 'gzip, deflate',
    'Referer': 'http://www.baidu.com',
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0',
}

#设置Cookie模拟登陆
cookie={'Cookie':'uuid_tt_dd=9355752249176600242_20180327; __yadk_uid=6BHVQvWYnoNxl3eLA9VqAKJDzcTsHk7N; kd_user_id=fa963059-44ce-48f6-9b11-db28f9c2f8dc; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=1788*1*PC_VC; UM_distinctid=1642bb7fd891ff-084f74390cc1c7-28792744-15aea-1642bb7fd8a1a7; CNZZDATA1272993679=430637425-1529739593-https%253A%252F%252Fblog.csdn.net%252F%7C1529739593; is_advert=Mon%2C%2015%20Jan%202255%2008%3A42%3A15%20GMT; TY_SESSION_ID=d524b848-bfa3-48df-9415-7da43ebcbfd0; ADHOC_MEMBERSHIP_CLIENT_ID1.0=923d341d-8a44-6b42-7269-aa78de1749a8; UserName=weixin_42141853; UserInfo=kWcYNbZy0%2B6z%2F%2BsM24JwP04fLQd0exodlLoFEsce8n7445vV4LzD9sBOWCu17CgAWLDaZFDI8e3ZRa8B6o0G8A%3D%3D; UserNick=Hello_Jandy; UN=weixin_42141853; AU=B92; BT=1530015086665; smidV2=201806261921224990b452919eb712d7a8052f6fa74e4c0015cd7a766149570; dc_session_id=10_1530002420268.196586; dc_tos=paxjbz; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1529758375,1529826531,1529887665,1530002525; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1530015264'
}

#设置代理IP
proxyLists = ['111.231.115.150:8888', '183.33.151.102:808','115.204.29.26:6666','118.190.95.269001:9001', '175.0.72.205:61202', '60.216.177.152:8118',
              '101.236.35.98:8866']
proxies ={'http': proxyLists[random.randrange(len(proxyLists))]}
url='https://blog.csdn.net/weixin_42141853'
data=requests.get(url,headers,cookies=cookie,proxies=proxies).text
pat='href="(https://blog.csdn.net/weixin_42141853/article/details.*?)"'
articalLists=re.findall(pat,data)
for i in range(1000):
    time.sleep(2)
    #文章路由
    articalurl = articalLists[random.randrange(len(articalLists))]
    #代理IP
    proxies = {'http': proxyLists[random.randrange(len(proxyLists))]}
    data = requests.get(articalurl, headers, cookies=cookie, proxies=proxies).text
    print(data)
    print(articalurl)
    print(proxies)
    print(i)


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值