Python:常见反爬策略及应对方案汇总

  

  

      Python:常见反爬策略及应对方案汇总”>
  
  <p>
  </p>
  <ul>
  <李>接受</李>
  <李>用户代理——三方库fake-useragent李</> </ul>
  <>之前得到fake_useragent  import  UserAgent
  时间=ua  UserAgent ()
  ua.ie
  #,Mozilla/5.0, (Windows;, U;, MSIE  9.0;, Windows  NT  9.0;, en - us);
  ua.msie
  #,Mozilla/5.0,(兼容;,MSIE  10.0;, Macintosh;, Intel  Mac  OS  X  10 _7_3;,三叉戟/6.0)& # 39;
  ua [& # 39; Internet  explorer # 39;】
  #,Mozilla/5.0,(兼容;,MSIE  8.0;, Windows  NT  6.1;,三叉戟/4.0;,GTB7.4;, InfoPath.2;, SV1;, .NET  CLR  3.3.69573;, WOW64;, en - us)
  ua.opera
  #,歌剧/9.80,(X11;, Linux  i686;, U;,俄文),转眼间/2.8.131 /11.11版本
  ua.chrome
  #,Mozilla/5.0, (Windows  NT  6.1), AppleWebKit/537.2, (KHTML, like 壁虎),Chrome/22.0.1216.0  Safari/537.2 & # 39;
  ua.google
  #,Mozilla/5.0, (Macintosh;, Intel  Mac  OS  X  10 _7_4), AppleWebKit/537.13, (KHTML, like 壁虎),Chrome/24.0.1290.1  Safari 537.13/ua [& # 39; google  chrome # 39;】
  #,Mozilla/5.0, (X11;, CrOS  i686  2268.111.0), AppleWebKit/536.11, (KHTML, like 壁虎),Chrome/20.0.1132.57  Safari 536.11/ua.firefox
  #,Mozilla/5.0, (Windows  NT  6.2;, Win64;, x64;,房车:16.0.1),壁虎/20121011,Firefox/16.0.1
  ua.ff
  #,Mozilla/5.0, (X11;, Ubuntu;, Linux  i686;,房车:15.0),壁虎/20100101,Firefox/15.0.1
  ua.safari
  #,Mozilla/5.0, (iPad;, CPU  OS  6 _0  like  Mac  OS  X), AppleWebKit/536.26, (KHTML, like 壁虎),版本/6.0,移动/10 a5355d  Safari 8536.25/#,以及从而best ,, random  via  real  world  browser  usage 统计
  ua.random </pre>
  <ul>
  <李类=引用页   <李类=" ql-indent-1 ">接受编码李   <李类=" ql-indent-1 ">接收语言   

  

  
      <李类=" ql-indent-1 ">有用的插件:EditThisCookie李   <李类=" ql-indent-1 ">如何处理脚本动态生成的饼干
  

  

  
      <李类=" ql-indent-1 ">硒+ WebDriver李   <李类=" ql-indent-1 ">铬/Firefox -司机李
  

  

  

  

  
      <李类=" ql-indent-1 ">在读取到隐藏域之前不要提交表单李   <李类=" ql-indent-1 ">用RoboBrowser这样的工具辅助提交表单
  

  

  
      <李> OCR(超正方体)——商业项目一般不考虑李   <李>专业识别平台,超级鹰/云打码李
  <>之前得到hashlib  import  md5   class  ChaoClient(对象):   ,def  __init__(自我,,用户名,密码,,soft_id):=,self.username 用户名=,,password  password.encode (& # 39; utf - 8 # 39;)   ,self.password =, md5(密码).hexdigest ()=,self.soft_id  soft_id   ,self.base_params =, {   ,& # 39;用户# 39;:,self.username,   ,& # 39;pass2& # 39;:, self.password,   ,& # 39;softid& # 39;:, self.soft_id,   ,}   ,self.headers =, {   ,& # 39;连接# 39;:,& # 39;保活# 39;   ,& # 39;用户代理# 39;:,& # 39;Mozilla/4.0,(兼容;,MSIE  8.0;, Windows  NT  5.1;,三叉戟/4.0)& # 39;,   ,}   ,def  post_pic(自我,,我,,codetype):   ,params =, {   ,& # 39;codetype& # 39;:, codetype,   ,}   ,params.update (self.base_params)   ,files =, {& # 39; userfile& # 39;:, (& # 39; captcha.jpg& # 39;,, im)}=,,r  requests.post (& # 39; http://upload.chaojiying.net/Upload/Processing.php& # 39;,, data=https://www.yisu.com/zixun/params,文件=文件,标题=self.headers)   返回r.json ()   if __name__==癬_main__”:   客户=ChaoClient(“用户名”、“密码”、“软件ID”)   张开(‘captcha.jpg’,‘rb)文件:   打印(客户端。post_pic(文件,1902))   

  

  
      <李类=" ql-indent-1 ">网页上有诱使爬虫爬取的爬取的隐藏链接(陷阱或蜜罐)   <李类=" ql-indent-1 ">通过硒+ WebDriver +铬判断链接是否可见或在可视区域李
  

  

  
      <李>代理服务——快代理/讯代理/芝麻代理/蘑菇代理/云代理李   <李>洋葱路由——国内需要   李才能使用
  <>以前yum  -y  install  tor   useradd  admin  -d /home/admin   passwd 管理   chown  -R 管理:admin /home/admin   chown  -R 管理:admin /var/运行/tor   tor

Python:常见反爬策略及应对方案汇总