其实网上有很多用python和php提取的教程了,而用python和php实现都有技术门槛,并不适合所有人,今天我就来跟大家介绍一种更简单的方式,但是也并不是没有门槛,需要会正则,利用DW正则替换。

<?xml version="1.0" encoding="utf-8"?>

<urlset>

    <url>

        <loc>https://m.10soo.com/</loc>

        <lastmod>2020-04-11</lastmod>

        <changefreq>daily</changefreq>

        <priority>1.0</priority>

    </url>

    <url>

        <loc>https://m.10soo.com/news.html</loc>

        <lastmod>2020-04-10</lastmod>

        <changefreq>daily</changefreq>

        <priority>0.8</priority>

    </url>

........

</urlset>

上面是通常情况下sitemap.xml的写法,其实用dw替换能替换掉大部分的内容,不规则的主要是<lastmod>2020-04-11</lastmod>和<priority>0.8</priority>中有不规则的数字,那么就先把他们改成规则的数字就好了,首先把-横线替换掉,所有<lastmod></lastmod>中间得到一串数字。

如何提取sitemap.xml中的url生成sitemap.txt

用同样的方式替换<priority></priority>中的数字替换为规则数字,然后利用正则替换,如下图:

如何提取sitemap.xml中的url生成sitemap.txt

替换的时候注意勾选 使用正则表达式,替换全部,就得到了纯url,另存成txt就达到目的了。

标签:石家庄小程序开发 sitemap 正则表达式 python php DW