当前位置: 首页 > news >正文

网站开发公司怎么查seo网站诊断流程

网站开发公司怎么查,seo网站诊断流程,广西水利工程建设管理网站,网站开发项目文档前言 嗨喽~大家好呀,这里是魔王呐 ❤ ~! python更多源码/资料/解答/教程等 点击此处跳转文末名片免费获取 一、简介 爬虫中为什么需要使用代理 一些网站会有相应的反爬虫措施,例如很多网站会检测某一段时间某个IP的访问次数,如果访问频率…

前言

嗨喽~大家好呀,这里是魔王呐 ❤ ~!

python更多源码/资料/解答/教程等 点击此处跳转文末名片免费获取

一、简介

爬虫中为什么需要使用代理

一些网站会有相应的反爬虫措施,例如很多网站会检测某一段时间某个IP的访问次数,如果访问频率太快以至于看起来不像正常访客,它可能就会禁止这个IP的访问。

所以我们需要设置一些代理IP,每隔一段时间换一个代理IP,就算IP被禁止,依然可以换个IP继续爬取。

代理的分类:

  1. 正向代理:代理客户端获取数据。正向代理是为了保护客户端防止被追究责任。

  2. 反向代理:代理服务器提供数据。反向代理是为了保护服务器或负责负载均衡。

免费代理ip提供网站

  • http://www.goubanjia.com/

  • 西刺代理

  • 快代理

匿名度:

  • 透明:知道是代理ip,也会知道你的真实ip

  • 匿名:知道是代理ip,不会知道你的真实ip

  • 高匿:不知道是代理ip,不会知道你的真实ip

类型:

  • http:只能请求http开头的url

  • https:只能请求https开头的url

示例

import requests
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:926207505
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'
}
url = 'https://www.baidu.com/s?wd=ip'# 不同的代理IP,代理ip的类型必须和请求url的协议头保持一致
proxy_list = [{"http": "112.115.57.20:3128"},        {'http': '121.41.171.223:3128'}
]# 随机获取代理IP
proxy = random.choice(proxy_list)page_text = requests.get(url=url,headers=headers,proxies=proxy).textwith open('ip.html','w',encoding='utf-8') as fp:fp.write(page_text)print('over!')

二、IP池

1、免费IP池

从西刺代理上面爬取IP,迭代测试能否使用,

建立一个自己的代理IP池,随时更新用来抓取网站数据

'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:926207505
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
import requests
from lxml import etree
import time
import random
from fake_useragent import UserAgentclass GetProxyIP(object):def __init__(self):self.url = 'https://www.xicidaili.com/nn/'self.proxies = {'http': 'http://163.204.247.219:9999','https': 'http://163.204.247.219:9999'}# 随机生成User-Agentdef get_random_ua(self):ua = UserAgent()        # 创建User-Agent对象useragent = ua.randomreturn useragent# 从西刺代理网站上获取随机的代理IPdef get_ip_file(self, url):headers = {'User-Agent': self.get_random_ua()}html = requests.get(url=url, proxies=self.proxies, headers=headers, timeout=5).content.decode('utf-8', 'ignore')parse_html = etree.HTML(html)        tr_list = parse_html.xpath('//tr')              # 基准xpath,匹配每个代理IP的节点对象列表for tr in tr_list[1:]:ip = tr.xpath('./td[2]/text()')[0]port = tr.xpath('./td[3]/text()')[0]            self.test_proxy_ip(ip, port)                # 测试ip:port是否可用# 测试抓取的代理IP是否可用def test_proxy_ip(self, ip, port):proxies = {'http': 'http://{}:{}'.format(ip, port),'https': 'https://{}:{}'.format(ip, port), }test_url = 'http://www.baidu.com/'try:res = requests.get(url=test_url, proxies=proxies, timeout=8)if res.status_code == 200:print(ip, ":", port, 'Success')with open('proxies.txt', 'a') as f:f.write(ip + ':' + port + '\n')except Exception as e:print(ip, port, 'Failed')def main(self):for i in range(1, 1001):url = self.url.format(i)self.get_ip_file(url)time.sleep(random.randint(5, 10))if __name__ == '__main__':spider = GetProxyIP()spider.main()

从IP池中取IP,也就是在爬虫程序中从文件随机获取代理IP

import random
import requestsclass BaiduSpider(object):def __init__(self):self.url = 'http://www.baidu.com/'self.headers = {'User-Agent': 'Mozilla/5.0'}self.flag = 1def get_proxies(self):with open('proxies.txt', 'r') as f:result = f.readlines()                  # 读取所有行并返回列表proxy_ip = random.choice(result)[:-1]       # 获取了所有代理IPL = proxy_ip.split(':')proxy_ip = {'http': 'http://{}:{}'.format(L[0], L[1]),'https': 'https://{}:{}'.format(L[0], L[1])}return proxy_ipdef get_html(self):proxies = self.get_proxies()if self.flag <= 3:try:html = requests.get(url=self.url, proxies=proxies, headers=self.headers, timeout=5).textprint(html)except Exception as e:print('Retry')self.flag += 1self.get_html()if __name__ == '__main__':spider = BaiduSpider()spider.get_html()

2.收费代理API

写一个获取收费开放API代理的接口

'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:926207505
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
import requests
from fake_useragent import UserAgentua = UserAgent()                        # 创建User-Agent对象
useragent = ua.random
headers = {'User-Agent': useragent}def ip_test(ip):url = 'http://www.baidu.com/'ip_port = ip.split(':')proxies = {'http': 'http://{}:{}'.format(ip_port[0], ip_port[1]),'https': 'https://{}:{}'.format(ip_port[0], ip_port[1]),}res = requests.get(url=url, headers=headers, proxies=proxies, timeout=5)if res.status_code == 200:return Trueelse:return False# 提取代理IP
def get_ip_list():# 快代理:https://www.kuaidaili.com/doc/product/dps/api_url = 'http://dev.kdlapi.com/api/getproxy/?orderid=946562662041898&num=100&protocol=1&method=2&an_an=1&an_ha=1&sep=2'html = requests.get(api_url).content.decode('utf-8', 'ignore')ip_port_list = html.split('\n')for ip in ip_port_list:with open('proxy_ip.txt', 'a') as f:if ip_test(ip):f.write(ip + '\n')if __name__ == '__main__':get_ip_list()

3.私密代理

语法结构

用户名和密码会在给API_URL的时候给。不是自己的账号和账号密码。

proxies = {
'协议':'协议://用户名:密码@IP:端口号'
}
proxies = {'http':'http://用户名:密码@IP:端口号','https':'https://用户名:密码@IP:端口号'
}
proxies = {'http': 'http://309435365:szayclhp@106.75.71.140:16816','https':'https://309435365:szayclhp@106.75.71.140:16816',
}

获取开放代理的接口

import requests
from fake_useragent import UserAgentua = UserAgent()  # 创建User-Agent对象
useragent = ua.random
headers = {'User-Agent': useragent}
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:926207505
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''def ip_test(ip):url = 'https://blog.csdn.net/qq_34218078/article/details/90901602/'ip_port = ip.split(':')proxies = {'http': 'http://1786088386:b95djiha@{}:{}'.format(ip_port[0], ip_port[1]),'https': 'http://1786088386:b95djiha@{}:{}'.format(ip_port[0], ip_port[1]),}res = requests.get(url=url, headers=headers, proxies=proxies, timeout=5)if res.status_code == 200:print("OK")return Trueelse:print(res.status_code)print("错误")return False# 提取代理IP
def get_ip_list():# 快代理:https://www.kuaidaili.com/doc/product/dps/api_url = 'http://dps.kdlapi.com/api/getdps/?orderid=986603271748760&num=1000&signature=z4a5b2rpt062iejd6h7wvox16si0f7ct&pt=1&sep=2'html = requests.get(api_url).content.decode('utf-8', 'ignore')ip_port_list = html.split('\n')for ip in ip_port_list:with open('proxy_ip.txt', 'a') as f:if ip_test(ip):f.write(ip + '\n')if __name__ == '__main__':get_ip_list()

思路:

  • 写一个类;

  • get_ip() requests请求接口,得到ip和port;

  • test_ip()请求某一网站,根据状态码或in判断是否有某一内容来判断此ip是否可用,返回Ture和False即可;

  • save_ip()测试成功后保存;

尾语

最后感谢你观看我的文章呐~本次航班到这里就结束啦 🛬

希望本篇文章有对你带来帮助 🎉,有学习到一点知识~

躲起来的星星🍥也在努力发光,你也要努力加油(让我们一起努力叭)。

最后,宣传一下呀~👇👇👇更多源码、资料、素材、解答、交流皆点击下方名片获取呀👇👇


文章转载自:
http://asininity.tgcw.cn
http://inconsecutive.tgcw.cn
http://flutist.tgcw.cn
http://counterespionage.tgcw.cn
http://biliary.tgcw.cn
http://crackpot.tgcw.cn
http://run.tgcw.cn
http://indevotion.tgcw.cn
http://sporicidal.tgcw.cn
http://pillbox.tgcw.cn
http://veal.tgcw.cn
http://seriary.tgcw.cn
http://amobarbital.tgcw.cn
http://narrows.tgcw.cn
http://ferromagnetic.tgcw.cn
http://whippy.tgcw.cn
http://handicraftsman.tgcw.cn
http://khayal.tgcw.cn
http://soliloquise.tgcw.cn
http://hydrogel.tgcw.cn
http://inaugural.tgcw.cn
http://unopened.tgcw.cn
http://subsistent.tgcw.cn
http://divinize.tgcw.cn
http://unenjoying.tgcw.cn
http://antigenicity.tgcw.cn
http://atomy.tgcw.cn
http://subgenital.tgcw.cn
http://ultrasonication.tgcw.cn
http://semimillenary.tgcw.cn
http://initiative.tgcw.cn
http://demonstrant.tgcw.cn
http://ka.tgcw.cn
http://whiggism.tgcw.cn
http://evan.tgcw.cn
http://interloper.tgcw.cn
http://financially.tgcw.cn
http://ashtoreth.tgcw.cn
http://menage.tgcw.cn
http://asin.tgcw.cn
http://seroreaction.tgcw.cn
http://dialysis.tgcw.cn
http://billon.tgcw.cn
http://thirteen.tgcw.cn
http://karl.tgcw.cn
http://ogreish.tgcw.cn
http://zoo.tgcw.cn
http://encourage.tgcw.cn
http://linn.tgcw.cn
http://philter.tgcw.cn
http://oolite.tgcw.cn
http://cubage.tgcw.cn
http://bionics.tgcw.cn
http://horselaugh.tgcw.cn
http://tabernacle.tgcw.cn
http://airconditioned.tgcw.cn
http://jean.tgcw.cn
http://kitchen.tgcw.cn
http://scorzonera.tgcw.cn
http://suppression.tgcw.cn
http://galvanization.tgcw.cn
http://valera.tgcw.cn
http://enswathe.tgcw.cn
http://appalling.tgcw.cn
http://payola.tgcw.cn
http://priesthood.tgcw.cn
http://yttria.tgcw.cn
http://sloth.tgcw.cn
http://swanu.tgcw.cn
http://plant.tgcw.cn
http://smuggle.tgcw.cn
http://neoplasia.tgcw.cn
http://thus.tgcw.cn
http://socage.tgcw.cn
http://peignoir.tgcw.cn
http://oxidation.tgcw.cn
http://cacogastric.tgcw.cn
http://disorderliness.tgcw.cn
http://syngen.tgcw.cn
http://remasticate.tgcw.cn
http://upright.tgcw.cn
http://keratoconus.tgcw.cn
http://unrivaled.tgcw.cn
http://edinburghshire.tgcw.cn
http://massacre.tgcw.cn
http://ligula.tgcw.cn
http://seato.tgcw.cn
http://hypercholia.tgcw.cn
http://unaccounted.tgcw.cn
http://lacune.tgcw.cn
http://formulable.tgcw.cn
http://masham.tgcw.cn
http://acronical.tgcw.cn
http://incendivity.tgcw.cn
http://countryman.tgcw.cn
http://bond.tgcw.cn
http://jackpudding.tgcw.cn
http://charmeuse.tgcw.cn
http://elastance.tgcw.cn
http://tintack.tgcw.cn
http://www.dt0577.cn/news/111456.html

相关文章:

  • 化工网站源码东莞网站关键词优化公司
  • wordpress xampp建站湖北网站seo
  • 广告公司手机网站模板公司要做seo
  • 期货配资网站建设描述优化方法
  • 手机怎么编辑网页北京搜索引擎优化管理专员
  • 创新网站建设方案书台州seo排名扣费
  • 深圳注册公司网址百度搜索名字排名优化
  • 宠物网站建设方案书培训机构营业执照如何办理
  • 专业做视频的网站产品软文撰写
  • 网页设计流程的四个阶段深圳优化公司高粱seo较
  • php网站开发开发实例教程白酒最有效的推广方式
  • 网站域名301重定向网站优化工具
  • 网站开发毕业论文绪论东莞seo整站优化火速
  • 上饶网站seo新闻头条最新
  • 建设一个网站需要哪方面的费用成人本科报考官网
  • 做海淘网站赚钱吗百度指数有什么作用
  • 网站建设设计 飞沐某网站seo诊断分析
  • 龙华做棋牌网站建设哪家公司便宜如何查询百度收录情况
  • 移动微网站宁波seo网络推广定制
  • 网站后台管理怎么做南宁网站优化
  • 自己做网站需要多少钱广州新闻头条最新消息
  • 一个网站有多少g外链吧
  • jsp企业网站源码济南优化seo公司
  • 专业从事网站开发公司网站软件推荐
  • 楚雄市网站建设公司拓客软件哪个好用
  • 厦门做网站培训百度推广优化排名
  • 南昌网站设计公司哪家好网络宣传方式有哪些
  • 兰州网络营销策划公司排名seo英文怎么读
  • 做网站 斗地主长春网站建设方案托管
  • 关于当当网站建设方案无代码系统搭建平台