首先,我们找到页面的url
点击下一页,观察url的变化
我们可以发现,page后面的值在发生变化,那么就直接上代码
import requests
import openpyxl
from bs4 import BeautifulSoup
lst = []
count=0
class Xiachufang():
def __init__(self):
self.url = 'https://www.xiachufang.com/explore/?page={0}'
self.headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'}
def send_requests(self, url):
resp = requests.get(url, headers=self.headers)
return resp.text
def parse_html(self,html):
global count
bs = BeautifulSoup(h