网站首页 包含标签 爬虫 的所有文章

  • 别去送死了!爬虫使用 Selenium 与 Puppeteer 能被网站探测的几十个特征

    很多人喜欢使用 Selenium 或 Puppeteer(Pyppeteer) 通过模拟浏览器来编写爬虫,自以为这样可以不被网站检测到,想爬什么数据就爬什么数据 但实际上,Selenium 启动的浏览器,有几十个特征可以被网站通过 JavaScript 探测到;Puppeteer 启动的浏览器,也有很多特征能够被网站探测 如果你不相信,那么我们来做一个实验。首先你使用正常的浏览器打开如下网址:https://bot.sannysoft.com/ 可以看到,页面的内容如下: 这个页面很长,你得滚动鼠标往下看,大部分都是绿色的 接下来,使用 Selenium启动一个 Chrome 的有头模式,再打开这个页面看看效果: 一开始 WebDriver这一项就标红了,说明网站成功检测到你使用模拟浏览器了 你再往下翻,标红的都是可以被检测出的特征 左边是普通浏览器,右边是模拟浏览器 左边是普通浏览器,右边是模拟浏览器 如果你一项一项对比,就会发现很多地方都不一样 这还是有头模式的效果。我们来看看无头模式: from selenium.webdriver import Chrome from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument("--headless") driver = Chrome('./chromedriver', options=chrome_options) driver.get('https://bot.sannysoft.com/') driver.save_screenshot('screenshot.png') 截图打开以后是下面这样的。不要吓到: 万里河山一片红 这么多特征都直接暴露了,你还隐藏个屁。网站只要想发现你,非常容易。 既然 Selenium 不行,那 Puppeteer 或者 Pyppeteer怎么样呢? 我们使用 Pyppeteer 来做个实验,直接启动无头模式并截图 运行效果是下面这样的: 跟 Selenium 没什么区别 所以,你还好意思继续用这两个东西来写爬虫? 爬点没有安全意识的小网站可以,爬那些有强大安全团队和法务团队的公司,你就是在找死! ...

    2021-02-19 834
  • Python爬虫之-爬取妹子图片

    #coding=utf-8 import requests from bs4 import BeautifulSoup import os all_url = ‘http://www.mzitu.com’ #http请求头 Hostreferer = { ‘User-Agent’:’Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)’, ‘Referer’:’http://www.mzitu.com’ } Picreferer = { ‘User-Agent’:’Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)’, ‘Referer’:’http://i.meizitu.net’ } #此请求头破解盗链 start_html = requests.get(all_url,headers = Hostreferer) #保存地址 path = ‘G:\python\妹子\liang’ #找寻最大页数 soup = BeautifulSoup(start_html.text,”html.parser”) page = soup.find_all(‘a’,class_=’page-numbers’) max_page = page[-2].text same_url = ‘http://www.mzitu.com/page/’ for n in range(1,int(max_page)+1): ul = same_url+str(n) start_html = requests.get(ul, headers = Hostreferer) soup = BeautifulSoup(start_html.text,”html.parser”) all_a = soup.find(‘div’,class_=’postlist’).find_all(‘a’,target=’_blank’) for a in all_a: title = a.get_text() #提取文本 if(title != ”): print(“准备扒取:”+title) #win不能创建带?的目录 if(os.path.exists(path+title.strip().replace(‘?’,”))): #print(‘目录已存在’) flag=1 else: os.makedirs(path+title.strip().replace(‘?’,”)) flag=0 os.chdir(path + title.strip().replace(‘?’,”)) href = a[‘href’] html = requests.get(href,headers = Hostreferer) mess = BeautifulSoup(html.text,”html.parser”) pic_max = mess.find_all(‘span’) pic_max = pic_max[10].text #最大页数 if(flag == 1 and len(os.listdir(path+title.strip().replace(‘?’,”))) >= int(pic_max)): print(‘已经保存完毕,跳过’) continue for num in range(1,int(pic_max)+1): pic = href+’/’+str(num) html = requests.get(pic,headers = Hostreferer) mess = BeautifulSoup(html.text,”html.parser”) pic_url = mess.find(‘img’,alt = title) print(pic_url[‘src’]) #exit(0) html = requests.get(pic_url[‘src’],headers = Picreferer) file_name = pic_url[‘src’].split(r’/’)[-1] f = open(file_name,’wb’) f.write(html.content) f.close() print(‘完成’) print(‘第’,n,’页完成’) ...

    2019-06-30 1611

联系我们

在线咨询:点击这里给我发消息

QQ交流群:KirinBlog

工作日:8:00-23:00,节假日休息

扫码关注