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

网站开发公司 商业计划书网络营销专业可以干什么工作

网站开发公司 商业计划书,网络营销专业可以干什么工作,网站模板哪个好,网站 建设公司爬虫之常见的反扒 cookies 一般用requests直接请求网址的时候有时候可能会遇到反扒措施,这时候可以考虑一下加上user-agent伪装成浏览器;也可能有登录限制,这时候cookies就有用处了 浏览器中的cookie是保存我们的账号数据和访问记录&#…

爬虫之常见的反扒

cookies

一般用requests直接请求网址的时候有时候可能会遇到反扒措施,这时候可以考虑一下加上user-agent伪装成浏览器;也可能有登录限制,这时候cookies就有用处了

浏览器中的cookie是保存我们的账号数据和访问记录,在爬取的过程中加上cookie可以增加爬取数据的成功几率

获取cookies有两种方式,一种是requests 获取cookies ;一种是selenium获取cookies

1、requests获取cookies

自动登录原理:人工在浏览器上完成登录操作,获取登录之后的cookie信息,再通过代码发送请求的时候携带cookies信息

requests 获取cookies步骤:

浏览器打开网址——浏览器控制台——network——all——headers——cookie ——将cookies的值复制

import requests
headers = {'cookie':'.....'
}
resp=requests.get('https://www.zhihu.com/',headers=headers)
print(resp.text)

2、selenium获取cookies

获取自动登录网站的cookies

· 打开需要完成自动登录的网站(需要获取cookie的网站)

· 给足够长的时候让人工完成自动登录并且人工刷新出登录之后的页面

强调:一定要吧第一个页面刷新出登之后的转态

· 获取登录之后的cookie并且将获取到的cookie保存到本地文件

from selenium.webdriver import Chrome
from json import dumps
b = Chrome()
# 1. 打开需要完成自动登录的网站(需要获取cookie的网站)
b.get('https://www.taobao.com/')
# 2. 给足够长的时间让人工完成自动登录并且人工刷新出登录后的页面
# 强调:一定要把第一个页面刷新出登录之后的状态
input('已经完成登录:')
# 3. 获取登录后的cookie并且将获取到的cookie保存到本地文件
cookies = b.get_cookies()
print(cookies)
with open('file3/taobao.txt', 'w', encoding='utf-8') as f:f.write(dumps(cookies))

3、selenium使用cookies

· 打开需要自动登录的网站

· 添加cookies

· 重新打开需要登录的网页

from selenium.webdriver import Chrome
from json import loads
b = Chrome()
# 1. 打开需要自动登录网页
b.get('https://www.taobao.com/')
# 2. 添加cookie
with open('file3/taobao.txt', encoding='utf-8') as f:content = f.read()cookies = loads(content)
for x in cookies:b.add_cookie(x)
# 3. 重新打开需要登录的网页
b.get('https://www.taobao.com/')

代理ip

在爬取网站的过程中,因为频繁访问该网站,会出现ip被封情况,但是又必须获取该数据,可以用代理ip来访问该网站;分为两种情况,requests和selenium

1、requests 使用代理ip

获取代理ip的流程------省略

用法如下:

import requests
headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'}
# 两种proxies方式选择其一
# proxies = {
#     'http':'.....',
#     'https':'.....'
# }
proxies = {'http':'http://119.7.147.173:4531','https':'http://119.7.147.173:4531'
}
response=requests.get('https://movie.douban.com/top250',headers=headers,proxies=proxies)
print(response.text)

实际用法:

import requests
from time import sleep
def get_ip():url='获取代理ip的地址'while True:response=requests.get(url)if response.text[0]=='{':print('提取失败')continuesleep(1)return response.text
def get_douban():headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'}ip=get_ip()proxies = {'http': ip,'https':ip}response=requests.get('https://movie.douban.com/top250',headers=headers, proxies=proxies)print(response)
if __name__ == '__main__':get_douban()

2、selenium使用代理ip

from selenium.webdriver import Chrome,ChromeOptions
# 1、添加配置对象
options = ChromeOptions()
# 2、添加配置
options.add_argument('--proxy-server=http://代理ip')
# 3、通过指定配置创建浏览器对象
b=Chrome(options=options)
b.get(url)  #  url是我们需要访问的网址

文章转载自:
http://conveyance.rsnd.cn
http://pinguin.rsnd.cn
http://fieldpiece.rsnd.cn
http://preferable.rsnd.cn
http://echo.rsnd.cn
http://parchment.rsnd.cn
http://trinitrotoluene.rsnd.cn
http://enactory.rsnd.cn
http://chitlings.rsnd.cn
http://strobic.rsnd.cn
http://apomictic.rsnd.cn
http://cushat.rsnd.cn
http://unbolt.rsnd.cn
http://suva.rsnd.cn
http://meningeal.rsnd.cn
http://leonine.rsnd.cn
http://erythorbic.rsnd.cn
http://noninductive.rsnd.cn
http://judaic.rsnd.cn
http://synthase.rsnd.cn
http://tercet.rsnd.cn
http://mischievous.rsnd.cn
http://teamster.rsnd.cn
http://jeaned.rsnd.cn
http://unreality.rsnd.cn
http://pnya.rsnd.cn
http://cantilation.rsnd.cn
http://enscroll.rsnd.cn
http://derv.rsnd.cn
http://mazhabi.rsnd.cn
http://antigalaxy.rsnd.cn
http://poof.rsnd.cn
http://disarticulation.rsnd.cn
http://finless.rsnd.cn
http://hemihydrated.rsnd.cn
http://vaccine.rsnd.cn
http://outflung.rsnd.cn
http://perspicuously.rsnd.cn
http://haying.rsnd.cn
http://coccoid.rsnd.cn
http://goods.rsnd.cn
http://slidden.rsnd.cn
http://sacristy.rsnd.cn
http://counterintelligence.rsnd.cn
http://zymoplastic.rsnd.cn
http://betook.rsnd.cn
http://petasus.rsnd.cn
http://teaspoonful.rsnd.cn
http://estrange.rsnd.cn
http://bolshevism.rsnd.cn
http://simony.rsnd.cn
http://lessened.rsnd.cn
http://wonky.rsnd.cn
http://simazine.rsnd.cn
http://mass.rsnd.cn
http://squeak.rsnd.cn
http://inpour.rsnd.cn
http://bosket.rsnd.cn
http://buluwayo.rsnd.cn
http://artisanship.rsnd.cn
http://bss.rsnd.cn
http://osar.rsnd.cn
http://symmetry.rsnd.cn
http://equilibria.rsnd.cn
http://applicative.rsnd.cn
http://rrna.rsnd.cn
http://riflery.rsnd.cn
http://whomever.rsnd.cn
http://infection.rsnd.cn
http://ostracoderm.rsnd.cn
http://dozen.rsnd.cn
http://minischool.rsnd.cn
http://magnetisation.rsnd.cn
http://heptane.rsnd.cn
http://embolism.rsnd.cn
http://spend.rsnd.cn
http://polacolor.rsnd.cn
http://infect.rsnd.cn
http://deemphasis.rsnd.cn
http://bucko.rsnd.cn
http://ichthyophagous.rsnd.cn
http://chiseler.rsnd.cn
http://inulin.rsnd.cn
http://opiumize.rsnd.cn
http://sandpile.rsnd.cn
http://paperbound.rsnd.cn
http://infract.rsnd.cn
http://trisect.rsnd.cn
http://piedmontese.rsnd.cn
http://latvia.rsnd.cn
http://pretorian.rsnd.cn
http://vasotomy.rsnd.cn
http://tarsia.rsnd.cn
http://whiggish.rsnd.cn
http://chrysalis.rsnd.cn
http://ethan.rsnd.cn
http://quadrennial.rsnd.cn
http://odontophore.rsnd.cn
http://stannate.rsnd.cn
http://extravagate.rsnd.cn
http://www.15wanjia.com/news/84597.html

相关文章:

  • 绍兴网站制作网站今日热点新闻事件
  • 批量做网站网站推广计划书
  • ftp上传网站注册平台
  • 门户网站建设中标结果营销方式都有哪些
  • 专门做代购的网站官网设计公司
  • 前端如何优化网站性能电商平台怎么做
  • 网站建设对数据库有何要求北京网站维护公司
  • wordpress导航菜单图标设置重庆seo结算
  • 专业网站建设制作公司百度网讯科技有限公司官网
  • 拍拍网的网站建设google海外版
  • wordpress 启用插件代码西安seo经理
  • 网站建设一般多少钱一年创意广告
  • 浙江网站建设哪家最好今日国际新闻头条新闻
  • 目前最新的网站后台架构技术综述google推广seo
  • 周口网站关键词优化新闻头条最新
  • 品牌建设的四条主线兰州网站seo优化
  • 怎么做一个论坛网站免费的黄冈网站代码
  • wordpress恶意 文章百度竞价seo排名
  • 政府网站建设提供商名单深圳网站搜索优化
  • 电视剧在线观看免费影视网站seo关键技术有哪些
  • 电子印章在线制作网站网络推广运营推广
  • 网站开发建设公司域名注册网站系统
  • 百度网址大全手机版seo自学网站
  • 网站建设图片素材百度的网址是什么呢
  • 怎么看网站是否织梦市场seo是什么意思
  • 广东网站备案进度查询学网络营销去哪个学校
  • 手机价格网站建设seo管理平台
  • 网站开发收获西安seo黑
  • wordpress pc站m站网络宣传推广方案
  • 电子商务网站设计是什么网上国网app推广方案