COM基础(续)


上一节没有谈到的一幅图:
class CFoo : public IFoo {
   void Func1() { /* ... */ }
   void Func2(int nCount) { /* ... */ }
};

客户端可能是:

#include <IFOO.H // Don't need CFoo, just the interface
void DoFoo() {
  IFoo *pFoo = Fn_That_Gets_An_IFoo_Pointer_To_A_CFoo_Object();

  // Call the methods.
  pFoo -> Func1();
  pFoo -> Func2(5);
};

图中调用的步骤是:

1,
pFoo is dereferenced to find the vtable pointer in the object.
2,


  1. The vtable pointer is dereferenced and indexed to find the address of the function to be called.

3,
The function is called.





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个基于 Python requests 库和 BeautifulSoup 库的简单的断点爬例子: ```python import requests from bs4 import BeautifulSoup # 设置基础 URL 和起始页码 base_url = 'https://example.com/page/' start_page = 1 # 设置一个空列表来存储所有爬取到的数据 data_list = [] # 开始循环爬取每一页的数据 for page in range(start_page, 100): # 构造当前页的完整 URL url = base_url + str(page) # 设置请求头部,模拟浏览器访问 headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36' } # 发送 HTTP GET 请求,获取页面内容 response = requests.get(url, headers=headers) # 判断响应状态码是否为 200 if response.status_code == 200: # 解析页面内容,获取需要的数据 soup = BeautifulSoup(response.content, 'html.parser') data = soup.find_all('div', {'class': 'data'}) # 将当前页爬取到的数据添加到总数据列表中 data_list.extend(data) # 输出提示信息 print('Successfully crawled page', page) # 等待一段时间,避免爬取过快被服务器封禁 IP time.sleep(2) else: # 如果响应状态码不为 200,说明请求失败,需要终止爬虫 print('Failed to crawl page', page) break # 将爬取到的所有数据保存到文件中 with open('data.txt', 'w') as f: for data in data_list: f.write(str(data) + '\n') ``` 上述代码中,我们首先设置了基础 URL 和起始页码,然后循环爬取每一页的数据。在每次爬取前,我们先构造当前页的完整 URL,然后发送 HTTP GET 请求获取页面内容。如果响应状态码为 200,说明请求成功,我们就解析页面内容,提取需要的数据,并将其添加到总数据列表中。如果响应状态码不为 200,说明请求失败,我们就需要终止爬虫。在每次爬取后,我们还添加了一个等待时间,避免爬取过快被服务器封禁 IP。最后,我们将爬取到的所有数据保存到文件中。如果需要断点爬,只需要保存当前已爬取的页码,然后在下次启动爬虫时从该页码开始即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值