关于小米
27岁,山西运城人,职业电商经理人,前端开发工作者,从事过网站建设、网络推广、SEO、SEM、信息流推广、二类电商、网络运维、软件开发,等相关电商工作,经验较为丰富,小米技术社区致力于为广大从事Web前端开发的人员提供一些力所能及的引导和帮助 ...[更多]
E-mail:mzze@163.com
Q Q:32362389
W X:xiaomi168527
关于王飞
27岁,山西运城人,职业电商经理人,网络工程师兼运维,从事过运营商网络建设,企业网络建设、优化。数据中心网络维护等通过,经验丰富,座右铭:当自己休息的时候,别忘了别人还在奔跑。 ...[更多]
关于小艳
大于花一样的年龄,河南郑州是我家,2010年在北京接触团购网,2011年进入天猫淘宝一待就是四年,如今已经将设计走向国际化(ps:误打误撞开始进入阿里巴巴国际站的设计,嘿嘿)五年电商设计,丰富经验,从事过天猫淘宝阿里各项设计,店铺运营,产品拍摄;我将我的经历与您分享是我的快乐!座右铭:越努力越幸运! ...[更多]
E-mail:97157726@qq.com
Q Q:97157726
d盘a目录下有1000个html文件,以后每天增加200个,现在要生成站点地图并每天更新
XML文件如下
<?xml version="1.0" encoding="utf-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> <loc>http://www.bbsmi.com/</loc> <changefreq>daily</changefreq> <priority>1.00</priority> </url> <url> <loc>http://www.bbsmi.com/a.html</loc> <changefreq>daily</changefreq> <priority>0.8</priority> </url> </urlset>
以后每天运行批处理的时候只用在,</urlset>上面添加如下格式即可
<url> <loc>http://www.bbsmi.com/文件名</loc> <changefreq>daily</changefreq> <priority>0.8</priority> </url> </urlset>
先获取当前文件夹下的所有html文件名,然后组合成网址,添加到xml中</urlset>上面,第二天只用添加新增的
@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
$xml = @'
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://www.bbsmi.com/</loc>
<changefreq>daily</changefreq>
<priority>1.00</priority>
</url>
{0}
</urlset>
'@
$url = @'
<url>
<loc>https://www.bbsmi.com//seo/{0}</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
'@
::加入回车
$endl = "`r`n"
$urls = ''
::获取当前目录下的.html文件 并列出每一个文件名保存
Get-ChildItem '*.html' | foreach { $urls += $url -f $_.Name }
::把url写入到$xml里面,并生成文件test.xml
$xml -f $urls | Out-File -Encoding utf8 'sitemap.xml'
'sitemap.xml'因为搜索引擎对xml数量和大小都有限制,如果文件过多就无法提交,所以我们要实现每超过1000即自动分为多个文件的写法
@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" &exit
$xml = @'
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://www.bbsmi.com/</loc>
<changefreq>always</changefreq>
<priority>1.00</priority>
</url>
{0}
</urlset>
'@
$url = @'
<url>
<loc>https://www.bbsmi.com//seo/{0}</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
'@
$endl = "`r`n"
::换行
$urls = @()
$n=(get-childitem *.html).count
for ($x=0 ; $x -le $n ; $x++) {
$urls += ""
}
::遍历栏目下的html名
$i=0
Get-ChildItem '*.html' | foreach {
$i+=1
$j=[math]::ceiling($i/2000)
$urls[$j] = $urls[$j] + $url -f $_.Name
}
::要多少个分一个文件就除以几 2000为例
for ($x=1 ; $x -le [math]::ceiling($n/2000) ; $x++) {
$xml -f $urls[$x] | Out-File -Encoding utf8 "test$x.xml"
}
::输出xml文件
::[math]::ceiling 序号是 1 2 3
::[math]::floor 序号是 0 1 2备注,因为编码写UTF8默认生成的编码是UTF-8 with bom,带bom的,很多站长平台不认,所以要把utf8改成 ASCII 即可

本站内容均为小米原创,转载请注明出处:小米技术社区>> 每天自动生成sitemap.xml的方法