Comments (2)
我们来讨论一下你在使用浏览器的访问一个网站的一些基本流程:
- 打开登录页面
- 填写登录信息后点登录
- 后续就可以正常访问了
那为什么登录一次之后就不需要再次登录了?因为后端可以鉴权,他知道你是谁,有没有登录。常用的有利用 cookie, access token。因为第一次登录完后,cookie 存到浏览器的 cookie 管理器里了,后面再次请求这个域名时会自动给带上cookie。当然现在很多 vue/ng/react 的应用使用 access token 也是一样的,token 存在本地的 localstorage,每次请求在header 里带上 token。
所以,每一次的请求都是一次 http 请求。你看到的 web 上很多正常的行为是因为它是浏览器,它帮你做了非常多的工作,比如 JS 引擎,他在运行 JS 的时候知道要再次发送 http 请求,把返回值操作 dom 重新渲染页面。
爬虫框架它不是一个浏览器,它需要做的是帮用户实现多线程、分布式、解析和存储等。当你发送一个 http 请求获取到 vue 的html 时,这个 html 里包含的 JS 框架是无法帮你渲染的,如果要实现,那就是再实现一个浏览器了...
那应该如何处理你的问题,要看你要采集的网站的后端设计。比如,如果他是 cookie 鉴权,且采没有很强的反爬,你可以写一个 chromedirver/playwight 等获取 cookie,当然你也可以直接写 http 去登录来获取 cookie。并把 cookie 设置到你后续所有需要请求的 Request 里面;access token 也是同理。
再就是你的说 vue 页面里用户操作才能看到的数据,这个当然任何爬虫框架不能帮你执行“操作”,那是 JS 绑定了元素,只有你操作了才会更新数据。你需要做的是 F12 查询他的 http 请求以及返回值,然后用 JSON PATH 解析数据。
一切都是 http 协议
from dotnetspider.
非常感谢作者详细的回答
from dotnetspider.
Related Issues (20)
- 关于启动多个爬虫时Builder中启动HostService HOT 3
- 如何往界面元素上填账号密码,
- [问题]爬取列表页API的场景 HOT 2
- 下载的html乱码
- [feature] 框架是否能自动生成Host request header HOT 3
- 怎样在DotnetSpider中使用PuppeteerSharp? HOT 1
- 发现宝藏
- 怎么使用sqlserver数据库呢 HOT 3
- 请求问题原因:Could not load type 'MySql.Data.MySqlClient.MySqlDbType' from assembly 'MySqlConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92 HOT 1
- DotnetSpider.Portal项目的lib资源目录在哪里,源码里没找到? HOT 2
- 我该如何获取多个元素 HOT 2
- 爬取一个日语酒店数据都是乱码 HOT 1
- Builder无法引用 HOT 3
- 重试的request请求它的Properties和headers被清理掉了,请问怎么解决 HOT 3
- 请问能用一个Spider,然后通过数据库进行配置不同抓取规则,进行多个网站抓取吗? HOT 1
- 自定义储存数据库问题 HOT 1
- XPathSelector内存消耗过大 HOT 3
- DataParser解析HTML的BUG HOT 1
- 用Host形式启动后,执行所有任务后仍在运行, 请问完成后怎么关闭 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnetspider.