Referer:防盗链,发送本地地址到服务器验证
Cookie、Set-cookie:缓存Cookie
模拟浏览器发送数据user-agent
User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.
安装http、cheerio(jquery核心模块),http.get请求网页
安装superagent,模拟浏览器ajax请求
安装selenium-webdriver,包含大多数浏览器驱动,可以条用浏览器返回数据
无界面浏览器
//执行过程中异常,需要手动编译gyp文件
//gyp目录下node-gyp configure(node.lib如果下载失败,拷贝cosole地址手动下载)
//再node-gyp build
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch(); //参数设置{headless:false}有界面
const page = await browser.newPage();
await page.goto('https://example.com'); //goto 添加参数{waitUntil: 'load',timeout: 0},避免navigation超时
await page.screenshot({path: 'example.png'});
await browser.close(); //关闭时会有正常的异常,不捕获就可以了
})();
page.$(selector)返回elementHandle元素,封装了单个元素的操作,click、focus等
page.content获取html
http短链接,cookie(客户端headers中cookie,服务端set-cookie)、session记录网页状态
await、async(async声明不创建线程)
async函数返回Promise对象,Promise包含resolved执行完、pending 正在执行、reject异常
thenable状态完成后,执行并返回Promise对象,链式调用
爬虫100例:https://mp.weixin.qq.com/s/a8Tky_u1u0A4vbssnAK2_g
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/daoer_sofu/article/details/100610250