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

如何把网站上线信息推广服务

如何把网站上线,信息推广服务,字体怎么安装wordpress,app 服务器 app爬虫(持续更新ing) # 网络请求 # url统一资源定位符(如:https://www.baidu.com) # 请求过程:客户端的web浏览器向服务器发起请求 # 请求又分为四部分:请求网址,请求方法&#xff08…

爬虫(持续更新ing)

# 网络请求
# url统一资源定位符(如:https://www.baidu.com)
# 请求过程:客户端的web浏览器向服务器发起请求
# 请求又分为四部分:请求网址,请求方法(get、post、put等),请求头,请求体
# 浏览器中一般都在f12中去看,推荐谷歌会清晰一点
# 爬虫概念:模拟浏览器发送请求获取响应
# 反爬概念:保护重要数据,阻止恶意网络攻击
# 反反爬:针对反爬做防御措施
# 爬虫的作用:1、数据采集 2、软件测试 3、抢票 4、网络安全 5、web漏洞扫描
# 通过爬取网站的数量分类:通用爬虫(如搜索引擎)、聚焦爬虫(如12306抢票)就是专门爬某个网站的数据, 通用爬虫爬取网站数量没有上线,聚焦爬虫:爬取网站数量有限,有明确目标
# 聚焦爬虫根据获取数据为目的分类:功能性爬虫、数据增量爬虫 功能性爬虫不获取数据,只为了实现某种功能,如投票、抢票、短信轰炸等 数据增量爬虫获取数据用于后续分析,url与数据同时变化,则整条新数据,url不变,数据变化,数据部分更新
# 爬虫基本流程:url->对url发送网络请求,获取浏览器的请求响应->解析响应,提取数据->保存数据
# robots协议,有些时候无法获取时,可以修改robots# 网络通信
# 浏览器:url
# DNS服务器:ip地址标注服务器
# DNS服务器返回ip地址给浏览器
# 浏览器拿到ip地址去访问服务器,返回响应
# 服务器返回的数据可能是js,hmtl,jpg等等
# 网络通信的实际原理:一个请求对一个数据包(文件)
# 之后抓包可能会有很多个数据包,共同组成了这个页面# http协议和https协议
# http协议规定了服务器和客户端互相通信的规则
# http协议:超文本传输协议,默认端口80
# 超文本:不仅仅限于文本,还可以是图片、音频、视频
# 传输协议:使用共用约定的固定格式来传递换成字符串的超文本内容
# https协议:http+ssl(安全套接字层) 默认端口443
# ssl对传输内容进行加密
# https比http更安全,但是性能更低
# http请求/响应的步骤:1、客户端连接web服务器 2、发送http请求 3、服务器接收请求返回响应 4、释放连接tcp连接 5、客户端解析html内容# 请求头
# 请求方式 get/post、put等
# get一般来说都是想服务器要数据的详情接口,而post一般是给服务器数据,提交接口
# user-agent:这个是模拟正常用户的操作关键	
# cookies:这个是登录保持,一般老一点的网站用这个,新的都用token
# referer:当前这一次请求是从哪个请求过来的

request模块

# 依赖安装 pip install requests
# 文本,html,css等字符串形式
import requests
url='https://www.baidu.com'
res=requests.get(url)
# text 这个方式内容会乱码,str类型,request模块自动根据http头部对响应编码做出有根据的推测
# res.encoding='utf-8' 当然你也可以指定编码类型
# print(res.text) 
# content bytes类型,可以通过decode进行解码 打印响应,这个是解码后的,默认进行utf-8
print(res.content.decode())
# 这个就是把这个内容保存为html
# with open('baidu.html','w',encoding='utf-8') as h:
#     h.write(res.content.decode())
#输出 这样就把所有的https://www.baidu.com请求拿到了
# 打印响应的url
print('url',res.url)
# 打印响应对象的请求头
print('request headers',res.request.headers)
# 打印响应头
print('res headers',res.headers)# 图片 把图片存到img下面
import requests
url='https://www.baidu.com/img/flexible/logo/pc/result.png'
res=requests.get(url)
with open('./img/jwq.png','wb') as img:img.write(res.content)# 模拟浏览器发送请求
import requests
url='https://www.baidu.com'
# 构建请求头 user-agent添加的目的是为了让服务器认为我们是浏览器发送的请求,而不是爬虫软件
headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
}
# headers参数接收字典形式的请求头
res=requests.get(url,headers=headers)
print(res.content.decode())
print(len(res.content.decode())) #查看这个响应内容的长度
print(res.request.headers) #查看响应对象的请求头# user-agent池 为了防止反爬
# 先演示手动添加的user_agents池
import requests
import random
url='https://www.baidu.com'
# 构建 user_agents池
user_agents = ['Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60','Opera/8.0 (Windows NT 5.1; U; en)','Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.50','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0','Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2 ','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11','Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36','Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)','Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 SE 2.X MetaSr 1.0','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0) ',
]
ua=random.choice(user_agents)
# 构建请求头 user-agent添加的目的是为了让服务器认为我们是浏览器发送的请求,而不是爬虫软件
headers={'user-agent':ua
}
# headers参数接收字典形式的请求头
res=requests.get(url,headers=headers)
# print(res.content.decode())
print(len(res.content.decode()))
print(res.request.headers)# 使用三方库 fake-useragent
# 安装 pip install fake-useragent
from fake_useragent import UserAgent
# 构建 user_agents池
ua = UserAgent()
# 获取随机浏览器用户代理字符串
print(ua.random)# 使用param携带参数 quote 明文转密文 unquote 密文转明文
import requests
from fake_useragent import UserAgent
from urllib.parse import quote,unquote
# quote 明文转密文
# unquote 密文转明文
# print(quote('学习'))
# print(unquote('%E5%AD%A6%E4%B9%A0'))
# 构建 user_agents池
ua = UserAgent()
url='https://www.baidu.com/s'
# 你要是不想使用params的话,你可以使用模板语法
# url=f'https://www.baidu.com/s?wd={name}'
#构建请求参数
name=input('请输入关键词:')
params={'wd':name
}
headers={'user-agent':ua.random
}
# 通过params携带参数
res=requests.get(url,headers=headers,params=params)
print(res.content.decode())# 获取网易云的图片
import requests
from fake_useragent import UserAgent
ua = UserAgent()
url='https://p1.music.126.net/_JcHT6u-TYhxjDbO3IhVQA==/109951170537166630.jpg?imageView&quality=89'
headers={# 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36''user-agent':ua.random
}
# 通过params携带参数
res=requests.get(url,headers=headers)
# print(res.content.decode())
with open('img/网易云.jpg','wb') as f:f.write(res.content)# 获取qq音乐音频
import requests
from fake_useragent import UserAgent
ua = UserAgent()
url='https://ws6.stream.qqmusic.qq.com/RS02064dfdIM38rSZY.mp3?guid=7976864250&vkey=AE4590431EAD34766DBAA9BA1A3715B3B45721EE23180669EA694EB7CA1F0DB4C8DE867A9883D4E897ED4E6F2ECF600CDFD34C78F2C07E09__v215192d1e&uin=554242051&fromtag=120052'
headers={# 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36''user-agent':ua.random
}
# 通过params携带参数
res=requests.get(url,headers=headers)
# print(res.content.decode())
with open('video/晴天.mp3','wb') as f:f.write(res.content)# 获取qq音乐mv
import requests
from fake_useragent import UserAgent
ua = UserAgent()
url='https://mv6.music.tc.qq.com/44B177558A20632E722F75FB6A67025F0BFC15AB98CC0B58FD3FC79E00B2EEDC9FAC3DF26DD0A319EACA6B2A30D24E2CZZqqmusic_default__v21ea05e5a/qmmv_0b53feaagaaao4ae4d5t4vtvikiaamuqaa2a.f9944.ts'
headers={# 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36''user-agent':ua.random
}
# 通过params携带参数
res=requests.get(url,headers=headers)
# print(res.content.decode())
with open('video/qq音乐.mp4','wb') as f:f.write(res.content)# 获取百度贴吧 翻页
import requests
from fake_useragent import UserAgent
ua = UserAgent()
url='https://tieba.baidu.com/f?'
name=input('请输入关键词:')
page=int(input('请输入要保存的页数:'))
for i in range(page):params = {'kw': name,'ie': 'utf-8','pn': 0}headers = {'user-agent': ua.random}# 通过params携带参数res = requests.get(url, headers=headers,params=params)# print(res.content.decode())with open(f'html/{name}{i+1}.html', 'wb') as f:f.write(res.content)# 获取百度贴吧转换为面向对象方式
import requests
from fake_useragent import UserAgent
class TieBa:def __init__(self):self.url='https://tieba.baidu.com/f?'self.headers = {'user-agent': UserAgent().random}# 发起请求def send(self,params):# 通过params携带参数res = requests.get(self.url, headers=self.headers,params=params)return res.text# 保存def save(self,page,con):with open(f'html/{page}.html', 'w',encoding='utf-8') as f:f.write(con)# 程序运行def run(self):name = input('请输入关键词:')pages = int(input('请输入要保存的页数:'))for page in range(pages):params = {'kw': name,'ie': 'utf-8','pn': pages * 50}data=self.send(params)self.save(page,data)
te =TieBa()
te.run()# 金山翻译 post
import requests
from fake_useragent import UserAgent
import jsonurl = 'https://ifanyi.iciba.com/index.php?c=trans'
headers = {'user-agent': UserAgent().random
}
name=input('请输入翻译内容:')
post_data = {'from': 'zh','to': 'en','q': name,
}
res = requests.post(url, headers=headers,data=post_data)
res.encoding = 'utf-8'
dict=json.loads(res.text)
print(dict['out'])# 下面就是中文的翻译
#输入 请输入翻译内容:中文
#输出 the Chinese language# 代理
# 分为正向代理和反向代理
# 正向代理:给客户端做代理,让服务器不知道客户端的真实身份(说句实在话就是保护自己的ip不会暴露,要封也是封代理ip)
# 反向代理:给服务器做代理,让浏览器不知道服务器的真实地址
# 正向代理保护客户端,反向代理保护服务端
# 实际上理论应该分为三类:透明代理(服务器知道我们使用了代理ip,也知道真实ip)、匿名代理(服务器能够检测到代理ip,但是无法知道真实ip)、高匿代理(服务器既不知代理ip,也不知道真实ip)
# proxies代理
import requests
from fake_useragent import UserAgent
url='https://www.baidu.com'
headers={'user-agent':UserAgent().random
}
# 构建代理字典
proxies={'http':'1.1.1.1:9527','https':'1.1.1.1:9527'
}
res=requests.get(url,headers=headers,proxies=proxies)
print(res.content.decode())

文章转载自:
http://spongy.c7493.cn
http://encaustic.c7493.cn
http://shiver.c7493.cn
http://snatchback.c7493.cn
http://allograft.c7493.cn
http://thegosis.c7493.cn
http://unworking.c7493.cn
http://lambda.c7493.cn
http://houselet.c7493.cn
http://oxygen.c7493.cn
http://umbrageous.c7493.cn
http://irrorate.c7493.cn
http://cheesemaker.c7493.cn
http://decoction.c7493.cn
http://counselee.c7493.cn
http://clabularium.c7493.cn
http://bighearted.c7493.cn
http://hyperopia.c7493.cn
http://interlocking.c7493.cn
http://cubit.c7493.cn
http://tolerably.c7493.cn
http://fastback.c7493.cn
http://silicium.c7493.cn
http://sweetheart.c7493.cn
http://lithophyte.c7493.cn
http://eradicable.c7493.cn
http://industrialist.c7493.cn
http://osi.c7493.cn
http://hippiatrical.c7493.cn
http://hepaticoenterostomy.c7493.cn
http://lamblike.c7493.cn
http://afire.c7493.cn
http://sard.c7493.cn
http://obedience.c7493.cn
http://kieselgur.c7493.cn
http://entocondyle.c7493.cn
http://otic.c7493.cn
http://audiophile.c7493.cn
http://lieder.c7493.cn
http://occidentally.c7493.cn
http://unquarried.c7493.cn
http://tola.c7493.cn
http://belgae.c7493.cn
http://fondle.c7493.cn
http://calibre.c7493.cn
http://achaea.c7493.cn
http://platoon.c7493.cn
http://eelpot.c7493.cn
http://sensa.c7493.cn
http://chengdu.c7493.cn
http://sightworthy.c7493.cn
http://crushable.c7493.cn
http://mower.c7493.cn
http://bikie.c7493.cn
http://waiwode.c7493.cn
http://lade.c7493.cn
http://dispeace.c7493.cn
http://ardency.c7493.cn
http://legendary.c7493.cn
http://microstomous.c7493.cn
http://rubicund.c7493.cn
http://backlighting.c7493.cn
http://baffle.c7493.cn
http://piave.c7493.cn
http://nativity.c7493.cn
http://fecundity.c7493.cn
http://hairbreadth.c7493.cn
http://umbles.c7493.cn
http://fertilize.c7493.cn
http://rigatoni.c7493.cn
http://fulham.c7493.cn
http://belgrade.c7493.cn
http://ultrafiche.c7493.cn
http://forepassed.c7493.cn
http://circle.c7493.cn
http://xanthoma.c7493.cn
http://bumpkin.c7493.cn
http://unnurtured.c7493.cn
http://neurosis.c7493.cn
http://genealogical.c7493.cn
http://engrain.c7493.cn
http://zine.c7493.cn
http://contradict.c7493.cn
http://kathiawar.c7493.cn
http://reprint.c7493.cn
http://paraplegic.c7493.cn
http://underclay.c7493.cn
http://wildwood.c7493.cn
http://irreparability.c7493.cn
http://cecf.c7493.cn
http://gangle.c7493.cn
http://disgregate.c7493.cn
http://mutuality.c7493.cn
http://question.c7493.cn
http://vitrescence.c7493.cn
http://polyether.c7493.cn
http://blubber.c7493.cn
http://stogie.c7493.cn
http://ritenuto.c7493.cn
http://hyponymy.c7493.cn
http://www.zhongyajixie.com/news/55064.html

相关文章:

  • 济南网站建设jnjy8网络营销中心
  • 白云网站 建设信科网络培训机构推荐
  • 无锡做网站企业营销型网站建设的价格
  • 有人做彩票网站吗seo公司费用
  • wordpress获取当前分类文章数有没有免费的seo网站
  • 3d报价网站开发天津百度快速排名优化
  • 做站用什么网站程序江西seo推广
  • 手机网站app制作seo培训赚钱
  • 网站开发策略网站自然优化
  • 黄江做网站东莞seo整站优化火速
  • 注册公司做网站站长工具星空传媒
  • 个性手绘个人网站模板下载网络运营和网络营销的区别
  • aspx网站做app品牌互动营销案例
  • 创建网站超链接广州最新疫情通报
  • 安徽定制型网站建设推广万网域名注册官网查询
  • 四川华海建设集团有限公司网站关键词优化排名费用
  • 营销网站主题有哪些内容河北百度seo软件
  • 湛江有没有做网站的2023网站seo
  • 做潮鞋的网站和平台上海b2b网络推广外包
  • 路易wordpress的主题西安seo顾问
  • 青海建设厅官方网站官网建站多少钱
  • 头条号链接其他网站怎么做朋友圈广告代理商官网
  • 企业网站托管技巧国产最好的a级suv
  • 茂名做网站公司搜索引擎营销的优缺点
  • 北京网站建设公司费用seo网络推广是干嘛的
  • wordpress怎么更换主题seo技术是什么意思
  • 网站设计做哪些的百度咨询
  • 网站去哪里备案电商软文广告经典案例
  • 图片做视频在线观看网站以营销推广为主题的方案
  • 做坏事网站百度排名推广