鱼C论坛

 找回密码
 立即注册
查看: 2666|回复: 1

写了个用ip代理刷百度知道浏览!有点问题求解答

[复制链接]
发表于 2015-2-19 23:00:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
写了个ip代理刷百度知道浏览量的,写完测试能抓到网页,但是浏览记录却不增加!这是为什么?代码如下:
  1. import os
  2. import re
  3. import urllib.request
  4. import random

  5. #获得ip代理网页的源文件
  6. def get_html(url):
  7.     res = urllib.request.Request(url)
  8.     res.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36')
  9.     html = urllib.request.urlopen(res).read().decode('utf-8')
  10.    
  11.     return html
  12.    
  13. #正则抓ip代理
  14. def get_ip(html):
  15.     z = r'(?:(?:[01]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d?\d|2[0-4]\d|25[0-5]):\d{2,4}'
  16.     iplist = re.findall(z,html)
  17.    
  18.     return iplist

  19. #要刷流量的网页地址
  20. def to_url(url,iplist):
  21.     proxy_support = urllib.request.ProxyHandler({'http':random.choice(iplist)})
  22.     opener = urllib.request.build_opener(proxy_support)
  23.     opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36')]
  24.     urllib.request.install_opener(opener)
  25.     html = urllib.request.urlopen(url).read().decode('gbk') #习惯写成这样的,方便测试
  26.     #print(html)

  27. if __name__ == '__main__':
  28.     url = 'http://zhidao.baidu.com/question/1605454116924284547.html'
  29.     iplist = get_ip(get_html('http://www.youdaili.net/Daili/guonei/3053.html'))
  30.     x = 1
  31.     for each in range(10):
  32.         try:
  33.             to_url(url,iplist)
  34.             print('访问成功%d次' % x)
  35.             x += 1
  36.         except:
  37.             print('访问出错!稍后继续')
  38.             continue
复制代码
前辈解答下吧!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2015-2-26 12:51:01 | 显示全部楼层
试了一下,不懂为什么没有增加访问量,或者是百度拦截了?不知道现在楼主有木有解决这个问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-14 22:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表