效果图如下:

1、进入你的后台,点击–外观—主题编辑器–先点击 functions.php 文件

把代码下面代码加入即可,无需修改,然后点击更新文件

//WordPress 站点显示页面加载时间、数据库查询次数及内存占用 - https://www.nmymz.com
function performance( $visible = false ) {
  $stat = sprintf( '本页生成数据库 %d 次查询,耗时 %.3f 秒,使用 %.2fMB 内存',
    get_num_queries(),
    timer_stop( 0, 3 ),
    memory_get_peak_usage() / 1024 / 1024
  );
  echo $visible ? $stat : "" ;
}

2、找到 footer.php文件 然后添加如下代码 然后点击更新

<center><?php if(function_exists(‘performance’)) performance(true) ;?></center>

回到页面,刷新一下就看到效果啦。

测试一段代码:

# -*- coding: utf-8 -*-
import time

import re
import requests
from bs4 import BeautifulSoup
import xlsxwriter
import urllib3

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.minimize_window()
#driver.get('https://www.1688.com/')
#driver.minimize_window()
#driver.get("file:///D:/Documents/WeChat%20Files/wxid_eq5u9v6vjko712/FileStorage/File/2020-11/1688html.html")
driver.get("file:///D:/1688.html")

#下面这行的数字4是抓取多少次,我这里是抓取多少页
for j in range(1):
print(j)
messageConfirm = input("第%s次抓取" %j)
print(f"messageConfirm = {messageConfirm}")
#公司名称:
company_name = driver.find_elements_by_class_name('company-name')
print("打印所有公司名称:")
messageConfirm = input("请输入任意内容并按回车键打印公司名称:")
#print(f"messageConfirm = {messageConfirm}")
companyList = []
if company_name:
for prname in company_name:
#print(type(prname))
companyList.append(prname.text)
#print(prname.text)
#print('公司名:',companyList)
#printGoodsList(companyList)

#产品名称
pro_title = driver.find_elements_by_xpath("//div[@class='desc-container']//div[@class='title']")
print("打印所有产品标题:")
messageConfirm = input("请按回车键打印产品标题")
print(f"messageConfirm = {messageConfirm}")
titleList = []
if pro_title:
for prname in pro_title:
#print(prname.text)
titleList.append(prname.text)
#产品价格
pro_price = driver.find_elements_by_xpath("//div[@class='desc-container']//div[@class='price']")
print("打印所有产品价格:")
messageConfirm = input("请按回车键打印产品价格")
print(f"messageConfirm = {messageConfirm}")
priceList = []
if pro_price:
for prname in pro_price:
#print(prname.text)
priceList.append(prname.text)

#产品成交多少
pro_sale = driver.find_elements_by_xpath("//div[@class='desc-container']//div[@class='sale']")
saleList = []
if pro_sale:
for prname in pro_sale:
# print(prname.text)
saleList.append(prname.text)
else:
saleList.append("okok")
#复购率
pro_rate = driver.find_elements_by_xpath("//div[@class='desc-container']//span[@class='shop-repurchase-rate']")
rateList = []
if pro_rate:
for prname in pro_rate:
# print(prname.text)
rateList.append(prname.text)

 

allList = []
allList.append(companyList+titleList+priceList+saleList+rateList)
print(allList)
#print(type(allList))
#print(allList[0][0])
#print(allList[0][10])

#tplt = '{:22}\t{:58}\t{:36}'
#print(tplt.format('公司名', '商品名', '价格'))
#for i in range(0,60):
# a = i + 1
#print("第%s次打印" %a)
# print(allList[0][i], "\t", allList[0][i + 60], "\t", allList[0][i + 120])
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。