18 กันยายน 2557

Published กันยายน 18, 2557 by with 0 comment

โปรแกรมสร้าง sitemap.xml โดยใช้ Python

สวัสดีครับทุกท่าน บทความนี้ผมจะไปรู้จักกับโปรแกรมที่มีชื่อว่า Python-Sitemap ใช้สร้าง sitemap.xml โดยใช้ Python 3 ครับ (โมดูลนี้ทำงานเฉพาะใน Python 3 เท่านั้นนะครับ)

Sitemap คืออะไร

Sitemap คือ แผนผังเว็บไซต์ เปรียบเสมือนแผนที่ของเว็บไซต์ ทำให้ Search Engine ต่าง ๆ ทราบถึงโครงสร้างของเว็บไซต์ ช่วยในการเก็บข้อมูลของ Search Engine เป็นไปอย่างรวดเร็วยิ่งขึ้น

การใช้งาน Python-Sitemap

ให้ผู้อ่านเข้าไปที่ https://github.com/c4software/python-sitemap 
แล้วกดดาวน์โหลด Download ZIP แล้วทำการแตกไฟล์ แล้วเข้าคอมมานด์ไลน์ ใช้คำสั่งเข้ามายังโฟล์เดอร์ที่แตกไฟล์ ZIP แล้วใช้คำสั่ง
>>> python main.py --domain ที่อยู่เว็บ --output sitemap.xml
เช่น
>>> python main.py --domain http://python3.wannaphong.com/ --output sitemap.xml
แล้วรอสักครู่ แค่นี้ก็จะได้ sitemap.xml แล้วครับ
รายละเอียดอื่น ๆ
config.json
>>> python main.py --config config.json

เปิดการ debug :
>>> python main.py --domain http://python3.wannaphong.com/ --output sitemap.xml --debug

เปิดใช้งานการรายงานสำหรับพิมพ์สรุปของ crawl:
>>> python main.py --domain http://python3.wannaphong.com --output sitemap.xml --report

ข้าม url (ตามนามสกุล) (ข้าม pdf และ xml url):
>>> python main.py --domain hhttp://python3.wannaphong.com --output sitemap.xml --skipext pdf --skipext xml 

วางเป็นส่วนหนึ่งของ url ผ่าน :
>>> python main.py --domain http://python3.wannaphong.com --output sitemap.xml --drop "id=[0-9]{5}"

แยก url โดยตัวกรองเป็นส่วนหนึ่งของมัน :
>>> python main.py --domain http://python3.wannaphong.com --output sitemap.xml --exclude "action=edit"

อ่าน robots.txt เพื่อเก็บเฉพาะบางลิงค์:
>>> python main.py --domain http://python3.wannaphong.com --output sitemap.xml --parserobots

การนำโปรแกรม Python-Sitemap ไปประยุกต์ใช้

  ผู้อ่านที่ใช้  Python ในการสร้างเว็บไซต์ สามารถนำโมดูลนี้ไปช่วยสร้าง  sitemap.xml เมื่อมีโพสต์ใหม่ ๆ ให้รันโปรแกรมนี้หลังที่บันทึกข้อมูล หรือ จะเขียนให้เก็บข้อมูลใหม่ ทุก ๆ 12 ซม. (เว็บที่มีความเคลื่อนไหวบ่อย เช่น เว็บบอร์ด เป็นต้นครับ)

ติดตามบทความต่อไปนะครับ
ขอบคุณครับ

0 ความคิดเห็น:

แสดงความคิดเห็น

แสดงความคิดเห็นได้ครับ :)