一、效果图
二、代码
import re from fake_useragent import UserAgent from lxml import etree import asyncio import aiohttp import pandas as pd # 定义一个类 定义使用的变量 定义get方法通过连接池进行网络请求 class LianjiaSpider(object): def __init__(self): self.ua = UserAgent() # 获取userAgent类 self.head = {"User-Agent": self.ua.random} self._data = list() # 初始化list async def get_page_count(self): result = await self.get("https://bj.lianjia.com/zufang/pg1") page_html = etree.HTML(result) # 解析网页 pageCount = page_html.xpath(".//div[@class='content__pg']/@data-totalpage") pageCount = list(map(int, pageCount)) return pageCount[0] async