PYTHON/API - AGENT AI - Workflow - SEO
Mục tiêu nên là:
SEO Expert → AI-powered SEO Operator → xây được các Agent AI tự động hóa quy trình SEO.
Bạn chỉ cần học Python/API đủ để đọc, sửa, kết nối, điều khiển và xây workflow AI, sau đó mới nâng dần lên mức tự viết Agent.
Tôi đề xuất lộ trình 16 tuần, thực chiến trên chính công việc SEO của Eric.
Lộ trình tổng thể
| Giai đoạn | Thời gian | Eric sẽ học | Sản phẩm thực chiến |
|---|---|---|---|
| 1. Python nền tảng | Tuần 1–3 | Python cơ bản | SEO utility scripts |
| 2. API & dữ liệu | Tuần 4–5 | REST API, JSON, HTTP | Tool lấy dữ liệu SEO |
| 3. AI API | Tuần 6–7 | OpenAI API, prompting, structured output | AI SEO tools |
| 4. Automation | Tuần 8–9 | File, CSV, Excel, crawling, scheduling | SEO automation |
| 5. Agent AI | Tuần 10–12 | Agent, tools, memory, workflow | SEO Agent v1 |
| 6. Multi-Agent SEO | Tuần 13–14 | Orchestration | SEO Agent team |
| 7. Production | Tuần 15–16 | Logging, error handling, deployment | Eric SEO AI System |
PHẦN I — TUẦN 1–3: PYTHON CHO SEO
Thời lượng: 1–1,5 giờ/ngày × 5 ngày/tuần.
Không cần học hết Python.
Tuần 1 — Python căn bản
Học:
-
print() - biến
- string
- number
- boolean
-
if/else -
for -
while - list
- dictionary
- function
Ví dụ đầu tiên:
keyword = "seo services vietnam" volume = 1200 position = 8 if position <= 10: print(keyword, "đang Top 10") else: print(keyword, "cần tối ưu")
Bài tập SEO
Tạo file:
seo_agent/ │ ├── lesson01/ │ ├── keywords.py │ ├── rankings.py │ └── content.py
Mục tiêu cuối tuần:
Nhìn một đoạn Python đơn giản và hiểu nó đang làm gì.
Tuần 2 — Python xử lý dữ liệu SEO
Đây là phần cực kỳ quan trọng với SEO.
Học:
- List
- Dictionary
- CSV
- Excel
- JSON
- đọc/ghi file
- lọc dữ liệu
- sort
- group dữ liệu
Ví dụ:
keywords = [ {"keyword": "seo agency", "position": 4}, {"keyword": "seo services", "position": 12}, {"keyword": "technical seo", "position": 18} ] for item in keywords: if 11 <= item["position"] <= 20: print(item["keyword"])
AI sau này sẽ dùng chính kiểu dữ liệu này.
Project 01
Keyword Opportunity Finder
Input:
keyword,volume,position seo agency,1200,8 seo services,800,14 technical seo,500,18
Python tự động:
- tìm keyword Top 11–20
- ưu tiên volume cao
- xuất danh sách opportunity.
Tuần 3 — Python thực chiến SEO
Học:
- function nâng cao
- module
- package
-
requests - exception
- regex cơ bản
- environment variables
Bắt đầu làm quen:
import requests url = "https://example.com" response = requests.get(url) print(response.status_code) print(response.text[:500])
Từ đây Eric bắt đầu hiểu:
Website → Request → API → Response → Python → AI
Project 02
SEO URL Checker
Nhập danh sách URL.
Python kiểm tra:
- HTTP status
- title
- meta description
- H1
- canonical
- robots
- word count.
PHẦN II — TUẦN 4–5: API
Đây là bước chuyển cực kỳ quan trọng.
Eric cần hiểu:
API = cách để phần mềm này nói chuyện với phần mềm khác.
Ví dụ:
Python ↓ API ↓ Google / OpenAI / Ahrefs / website ↓ JSON ↓ Python
Tuần 4 — REST API
Học:
- HTTP
- GET
- POST
- PUT
- DELETE
- Header
- API Key
- endpoint
- parameter
- JSON
- status code
Ví dụ:
import requests response = requests.get( "https://api.example.com/data" ) data = response.json() print(data)
Phải hiểu được:
Endpoint API Key Request Response JSON
Project 03
Tạo:
SEO API Collector
Python nhận:
URL
→ gọi API
→ nhận JSON
→ lưu thành:
url,title,status,h1
Tuần 5 — API SEO
Bắt đầu nghiên cứu API của các hệ thống Eric đang dùng.
Ưu tiên:
- Google Search Console API
- Google Analytics
- Ahrefs API
- DataForSEO hoặc tương đương
- OpenAI API
Mục tiêu không phải học từng API thuộc lòng.
Mục tiêu là:
Đọc documentation → lấy API key → gọi endpoint → xử lý JSON.
PHẦN III — TUẦN 6–7: AI API
Đây mới là phần biến Python thành AI SEO automation.
Eric học:
Python ↓ OpenAI API ↓ LLM ↓ Structured Output ↓ Python xử lý
Ví dụ conceptual:
keyword = "seo services vietnam" prompt = f""" Analyze this keyword: {keyword} Return: - search intent - content type - target audience - recommended title """
AI trả:
{ "intent": "commercial", "content_type": "service page", "audience": "business owners", "title": "SEO Services in Vietnam..." }
Python tiếp tục xử lý.
Tuần 6 — Prompt + AI API
Học:
- system prompt
- user prompt
- context
- temperature
- token
- structured output
- JSON output
- function/tool calling ở mức cơ bản
Project 04
AI Keyword Classifier
Input:
keyword seo agency seo services how seo works technical seo audit
AI phân loại:
Search Intent Funnel Stage Content Type Business Value
Tuần 7 — AI Content Analyst
Xây:
AI Content Auditor
Input:
URL
Python:
- Crawl page
- lấy content
- gửi AI
- AI phân tích
- xuất report.
Report:
Content Score Search Intent E-E-A-T Topical Coverage Missing Entities Missing Questions Internal Link Opportunities AI Search Visibility Recommendations
Đây đã là AI SEO tool thật sự.
PHẦN IV — TUẦN 8–9: AUTOMATION
Đây là nơi bắt đầu giảm công việc thủ công của team.
Eric học:
- pandas
- openpyxl
- CSV
- folder automation
- batch processing
- crawling
- logging
- scheduling
Tuần 8 — Batch SEO
Thay vì:
1 URL → 1 lần
làm:
500 URL ↓ Python ↓ crawl ↓ AI ↓ audit ↓ Excel
Project 05
Bulk Content Audit Agent
Input:
url url1 url2 url3 ...
Output:
SEO_AUDIT.xlsx
Có:
- Title
- H1
- Meta
- Intent
- Content quality
- E-E-A-T
- Entity
- Internal links
- Recommendations
- Priority.
Tuần 9 — SEO Automation Pipeline
Xây pipeline:
Keyword ↓ Keyword clustering ↓ Search intent ↓ SERP analysis ↓ Content brief ↓ Content creation ↓ On-page audit ↓ Internal linking ↓ Publishing ↓ GSC monitoring
Eric bắt đầu suy nghĩ như AI System Architect, thay vì chỉ là SEO Specialist.
PHẦN V — TUẦN 10–12: AGENT AI SEO
Đây là mục tiêu chính.
Eric cần phân biệt:
Automation
A → B → C → D
AI Workflow
A ↓ AI quyết định ↓ B/C/D
Agent
Goal ↓ AI tự lập kế hoạch ↓ chọn Tool ↓ thực hiện ↓ kiểm tra ↓ sửa ↓ hoàn thành Goal
Tuần 10 — Agent cơ bản
Agent có:
Brain Tools Memory Instructions Goal
Ví dụ:
SEO Keyword Agent
Goal:
Tìm cơ hội keyword mới cho website.
Tools:
GSC API Ahrefs API Google SERP data Python OpenAI
Agent:
Lấy dữ liệu ↓ phân tích ↓ phát hiện opportunity ↓ đánh giá business value ↓ đề xuất action
Tuần 11 — SEO Agent có Tools
Đây là bài quan trọng nhất.
Eric xây:
SEO Research Agent
Tools:
get_gsc_data() get_keywords() get_serp() crawl_url() analyze_content() cluster_keywords()
Agent quyết định:
Cần dữ liệu GSC? → gọi GSC Cần SERP? → gọi SERP tool Cần đọc website? → crawl Cần phân tích? → AI
Đây chính là nền tảng của Agentic SEO.
Tuần 12 — SEO Agent v1
Project lớn đầu tiên:
Eric SEO Agent v1
Input:
Website
Agent tự thực hiện:
1. Crawl website 2. lấy sitemap 3. lấy GSC 4. phân tích keyword 5. phân tích content 6. tìm keyword opportunity 7. tìm content gap 8. tìm technical issue 9. tìm internal link opportunity 10. tạo SEO roadmap
Output:
SEO Executive Report
PHẦN VI — TUẦN 13–14: MULTI-AGENT
Đây là nơi hệ thống bắt đầu giống một team SEO AI.
Thay vì một Agent làm tất cả:
Eric SEO Manager Agent │ ┌──────────────┼──────────────┐ ↓ ↓ ↓ Research Agent Technical Agent Content Agent ↓ ↓ ↓ Keyword Technical Content SERP Audit Strategy │ │ │ └──────────────┼──────────────┘ ↓ SEO Strategy Agent ↓ Final Report
Agent 1 — Research
- keyword research
- competitor
- SERP
- content gap
Agent 2 — Technical
- crawl
- indexability
- schema
- canonical
- sitemap
- internal link
Agent 3 — Content
- content brief
- entity
- topical coverage
- E-E-A-T
- AI Search
Agent 4 — Strategist
Tổng hợp.
PHẦN VII — TUẦN 15–16: PRODUCTION
Đừng dừng ở demo.
Eric cần học:
Error handling
API lỗi → retry → log → tiếp tục
Logging
Biết:
Agent đã làm gì? Tool nào được gọi? API nào lỗi? Chi phí bao nhiêu? Kết quả gì?
Security
Không viết:
api_key = "sk-xxxxx"
Mà dùng:
.env environment variables
Deployment
Sau này có thể đưa Agent lên:
Cloud Server Docker Streamlit FastAPI
để team sử dụng.
🎯 7 PROJECT ERIC NÊN HOÀN THÀNH
Tôi không muốn Eric học Python bằng 100 bài tập vô nghĩa.
Hãy học bằng 7 sản phẩm:
| Project | Mục tiêu |
|---|---|
| 01 | Keyword Opportunity Finder |
| 02 | SEO URL Checker |
| 03 | SEO API Collector |
| 04 | AI Keyword Classifier |
| 05 | Bulk Content Auditor |
| 06 | SEO Research Agent |
| 07 | Eric SEO AI Agent |
Project số 7 là mục tiêu cuối.
Kiến trúc Eric SEO AI về lâu dài
Tôi khuyên Eric hướng tới kiến trúc:
ERIC SEO AI │ ┌────────┴────────┐ │ AI Manager │ └────────┬────────┘ │ ┌─────────────────┼─────────────────┐ ↓ ↓ ↓ Research Agent Technical Agent Content Agent │ │ │ ↓ ↓ ↓ GSC / Ahrefs Crawler / Schema Content DB SERP / Trends Sitemap / Links OpenAI │ │ │ └─────────────────┼─────────────────┘ ↓ Strategy Agent ↓ SEO Action Plan ↓ Human Approval ↓ Execution
Lưu ý quan trọng: giai đoạn đầu không cho Agent tự publish/delete/change website. Hãy để:
AI đề xuất → Eric/team duyệt → hệ thống thực thi.
Sau khi hệ thống ổn định mới tự động hóa sâu hơn.
🗓️ Lịch học hàng ngày
Tôi đề xuất Eric học theo công thức:
90 phút/ngày
20 phút — học
Python/API concept.
20 phút — code
Tự gõ code, không copy-paste.
40 phút — project SEO
Áp dụng ngay vào một bài toán thật.
10 phút — ghi chú
Ghi lại:
Hôm nay tôi học gì? Tôi gặp lỗi gì? Tôi giải quyết thế nào? Có thể tự động hóa SEO nào?
Quy tắc học cực kỳ quan trọng
Eric không cần trở thành Python Developer.
Mục tiêu:
Level 1
Đọc Python
↓
Level 2
Sửa Python
↓
Level 3
Viết Python đơn giản
↓
Level 4
Kết nối API
↓
Level 5
Gọi AI
↓
Level 6
Build AI workflow
↓
Level 7
Build Agent
↓
Level 8
Build AI SEO system
Đừng cố học Level 8 ngay từ đầu.
Bộ công nghệ nên học
Tôi sẽ giới hạn stack, tránh học lan man:
Python │ ├── requests ├── pandas ├── BeautifulSoup ├── Playwright ├── openpyxl │ ├── REST API ├── JSON ├── .env │ ├── OpenAI API │ ├── FastAPI │ ├── Git/GitHub │ └── Agent framework
Sau này mới bổ sung:
PostgreSQL Vector DB Docker Cloud MCP Multi-Agent
Và tôi muốn Eric học theo một dự án duy nhất
Thay vì học:
"Hôm nay học Python."
Hãy đặt câu hỏi:
"Hôm nay tôi học Python để tự động hóa việc SEO nào?"
Ví dụ:
Ngày 1
Python variables
→ để xử lý keyword.
Ngày 7
Dictionary
→ để lưu SEO data.
Ngày 20
requests
→ để gọi API.
Ngày 35
OpenAI API
→ để AI phân tích keyword.
Ngày 60
Tool calling
→ để Agent sử dụng GSC/Ahrefs/crawler.
Ngày 90
Agent
→ để tự thực hiện SEO research.
Đó mới là con đường phù hợp với mục tiêu Eric SEO → AI SEO Expert.
--------------------------------------------------------
TUẦN 1
Được. Với Tuần 1, tôi muốn Eric học theo kiểu “học đến đâu dùng được cho SEO đến đó”, không học Python hàn lâm.
Mục tiêu cuối tuần là Eric có thể tự viết một chương trình Python nhỏ để:
Nhập danh sách keyword → Python phân tích dữ liệu → phân loại keyword theo vị trí/volume → xuất kết quả.
Đây chính là nền móng để sau này chúng ta thay Python bằng AI Agent + API.
TUẦN 1 — PYTHON CĂN BẢN CHO SEO
🎯 Mục tiêu sau 7 ngày
Eric cần hiểu và sử dụng được:
Biến ↓ String / Number / Boolean ↓ List ↓ Dictionary ↓ if / elif / else ↓ for ↓ Function ↓ Xử lý dữ liệu SEO
Và cuối tuần hoàn thành:
Project 01 — SEO Keyword Analyzer
Ví dụ:
Input: seo agency volume 1200 position 8 seo services volume 800 position 14 technical seo volume 500 position 18 seo audit volume 300 position 25
Python tự phân tích:
seo agency → TOP 10 seo services → OPPORTUNITY technical seo → OPPORTUNITY seo audit → NEED IMPROVEMENT
1. TRƯỚC TIÊN: ERIC SẼ CODE Ở ĐÂU?
Tôi khuyên Eric sử dụng:
VS Code
Đây sẽ là công cụ chính để học và sau này xây Agent AI.
Eric đã có thư mục:
C:\Users\PC\Desktop\seo-agent
Chúng ta sẽ tiếp tục dùng chính thư mục này.
Cấu trúc tuần 1:
Desktop └── seo-agent │ ├── week01 │ ├── lesson01.py │ ├── lesson02.py │ ├── lesson03.py │ ├── lesson04.py │ ├── lesson05.py │ └── seo_keyword_analyzer.py │ └── README.md
2. KIỂM TRA PYTHON ĐÃ CÀI CHƯA
Mở Command Prompt.
Eric sẽ thấy:
C:\Users\PC>
Gõ:
python --version
Nếu hiện:
Python 3.x.x
là được.
Ví dụ:
Python 3.13.7
Nếu python is not recognized..., báo tôi kết quả đó. Chúng ta sẽ xử lý bước cài Python.
3. MỞ THƯ MỤC SEO-AGENT
Trong CMD:
cd Desktop\seo-agent
Sau đó:
code .
Nếu VS Code mở thư mục seo-agent → thành công.
Nếu code is not recognized, cũng báo tôi.
4. TẠO FILE ĐẦU TIÊN
Trong VS Code:
seo-agent ↓ New Folder ↓ week01
Sau đó tạo:
lesson01.py
Đây là chương trình Python đầu tiên.
🟢 BÀI 1 — print()
4.1. print() là gì?
print() nghĩa đơn giản:
Hiển thị thông tin ra màn hình.
Gõ:
print("Hello Eric SEO")
Lưu file:
Ctrl + S
Chạy bằng Terminal:
python lesson01.py
Kết quả:
Hello Eric SEO
🎯 Đây là chương trình Python đầu tiên của Eric.
5. THỬ VỚI SEO
Xóa code cũ và viết:
print("Eric SEO") print("SEO Specialist") print("AI SEO") print("Agent AI SEO")
Chạy:
python lesson01.py
Kết quả:
Eric SEO SEO Specialist AI SEO Agent AI SEO
6. COMMENT — GHI CHÚ TRONG CODE
Thêm:
# Đây là chương trình Python đầu tiên của Eric SEO print("Eric SEO")
Python sẽ bỏ qua dòng bắt đầu bằng #.
Comment rất quan trọng khi project lớn.
Ví dụ:
# Kiểm tra keyword có nằm trong Top 10 không print("SEO Agency")
🟢 BÀI 2 — BIẾN
Đây là kiến thức cực kỳ quan trọng.
Hãy tưởng tượng Python có những cái hộp.
keyword volume position
Mỗi cái hộp chứa một giá trị.
Ví dụ:
keyword = "seo agency" volume = 1200 position = 8
Ta có:
keyword → "seo agency" volume → 1200 position → 8
Sau đó:
print(keyword) print(volume) print(position)
Kết quả:
seo agency 1200 8
7. BÀI TẬP ĐẦU TIÊN
Eric tự gõ:
keyword = "seo services vietnam" volume = 1000 position = 7 print(keyword) print(volume) print(position)
Chạy:
python lesson01.py
Kết quả:
seo services vietnam 1000 7
8. TẠI SAO BIẾN QUAN TRỌNG VỚI SEO?
Sau này API có thể trả về:
{ "keyword": "seo agency", "volume": 1200, "position": 8 }
Python có thể biến thành:
keyword = "seo agency" volume = 1200 position = 8
Rồi AI xử lý.
Đó là lý do Eric phải hiểu variable.
🟢 BÀI 3 — STRING
String = dữ liệu dạng chữ.
Ví dụ:
keyword = "seo agency" title = "Best SEO Agency in Vietnam" country = "Vietnam"
String nằm trong:
""
hoặc:
''
Ví dụ:
keyword = "seo agency"
9. NỐI CHUỖI
Eric thử:
keyword = "seo agency" print("Keyword:", keyword)
Kết quả:
Keyword: seo agency
Có thể dùng f-string:
keyword = "seo agency" volume = 1200 position = 8 print(f"Keyword: {keyword}") print(f"Volume: {volume}") print(f"Position: {position}")
Đây là cách Eric sẽ dùng rất nhiều.
10. BÀI TẬP SEO
Tự tạo:
website = "eric-seo.blogspot.com" keyword = "seo expert" position = 5 print(f"Website: {website}") print(f"Keyword: {keyword}") print(f"Position: {position}")
🟢 BÀI 4 — NUMBER
Python có thể xử lý số.
volume = 1200 position = 8 traffic = 3500
Ta có thể tính toán:
volume = 1200 position = 8 print(volume + 100) print(position + 1)
Kết quả:
1300 9
11. TOÁN TỬ CƠ BẢN
Eric cần biết:
+ cộng - trừ * nhân / chia
Ví dụ:
traffic = 10000 conversion_rate = 0.03 conversions = traffic * conversion_rate print(conversions)
Kết quả:
300
Đây chính là tư duy automation.
🟢 BÀI 5 — BOOLEAN
Boolean chỉ có:
True False
Ví dụ:
is_indexed = True has_schema = False
Sau này cực kỳ hữu ích khi audit SEO:
is_indexed = True has_title = True has_h1 = False
Python có thể đưa ra kết luận.
🟢 BÀI 6 — IF / ELSE
Đây là lúc Python bắt đầu ra quyết định.
Ví dụ:
position = 8 if position <= 10: print("TOP 10") else: print("Not Top 10")
Kết quả:
TOP 10
Đổi:
position = 15
Kết quả:
Not Top 10
12. HIỂU TƯ DUY IF
Cấu trúc:
IF điều kiện: làm việc A ELSE: làm việc B
Ví dụ SEO:
Nếu keyword Top 10 → giữ và tối ưu Nếu keyword Top 11–20 → ưu tiên SEO Nếu keyword > 20 → cần đánh giá lại
13. BÀI TẬP SEO
Eric tự viết:
position = 15 if position <= 10: print("Keyword is Top 10") else: print("Keyword needs optimization")
Sau đó thử:
position = 3 position = 10 position = 11 position = 20 position = 21
Quan sát kết quả.
🟢 BÀI 7 — elif
Chúng ta cần 3 trường hợp:
position = 15 if position <= 10: print("TOP 10") elif position <= 20: print("OPPORTUNITY") else: print("NEEDS IMPROVEMENT")
Kết quả:
OPPORTUNITY
Đây chính là logic đầu tiên của:
Keyword Opportunity Finder
14. QUY TẮC SEO
Eric có thể đặt:
1–10 → TOP 10 11–20 → QUICK WIN 21–50 → NEED OPTIMIZATION >50 → LOW PRIORITY
Code:
position = 17 if position <= 10: print("TOP 10") elif position <= 20: print("QUICK WIN") elif position <= 50: print("NEED OPTIMIZATION") else: print("LOW PRIORITY")
🟢 BÀI 8 — LIST
Bây giờ chúng ta không muốn chỉ xử lý một keyword.
Ta có:
seo agency seo services technical seo seo audit
List cho phép chứa nhiều dữ liệu.
keywords = [ "seo agency", "seo services", "technical seo", "seo audit" ]
In:
print(keywords)
15. LẤY TỪNG PHẦN TỬ
Python đánh số từ 0.
keywords = [ "seo agency", "seo services", "technical seo" ]
Ta có:
0 → seo agency 1 → seo services 2 → technical seo
Ví dụ:
print(keywords[0]) print(keywords[1]) print(keywords[2])
🟢 BÀI 9 — FOR LOOP
Đây là một trong những thứ Eric sẽ sử dụng nhiều nhất.
keywords = [ "seo agency", "seo services", "technical seo" ] for keyword in keywords: print(keyword)
Python sẽ chạy:
seo agency seo services technical seo
Tư duy:
FOR mỗi keyword → PRINT keyword
16. KẾT HỢP FOR + IF
Đây là lúc bắt đầu có giá trị SEO thực tế.
keywords = [ ("seo agency", 5), ("seo services", 14), ("technical seo", 18), ("seo audit", 32) ] for keyword, position in keywords: if position <= 10: print(keyword, "→ TOP 10") elif position <= 20: print(keyword, "→ QUICK WIN") else: print(keyword, "→ NEED OPTIMIZATION")
Kết quả:
seo agency → TOP 10 seo services → QUICK WIN technical seo → QUICK WIN seo audit → NEED OPTIMIZATION
🎯 Eric vừa viết được một SEO automation nhỏ.
🟢 BÀI 10 — DICTIONARY
Bây giờ chúng ta cần dữ liệu đầy đủ hơn.
Một keyword có:
keyword volume position traffic intent
Dictionary phù hợp hơn.
keyword = { "keyword": "seo agency", "volume": 1200, "position": 8, "traffic": 350 }
Lấy dữ liệu:
print(keyword["keyword"]) print(keyword["volume"]) print(keyword["position"])
17. NHIỀU KEYWORD
keywords = [ { "keyword": "seo agency", "volume": 1200, "position": 8 }, { "keyword": "seo services", "volume": 800, "position": 14 }, { "keyword": "technical seo", "volume": 500, "position": 18 } ]
Đây chính là cấu trúc dữ liệu Eric sẽ gặp khi làm việc với API.
18. FOR + DICTIONARY
for item in keywords: print(item["keyword"]) print(item["volume"]) print(item["position"]) print("---")
Kết quả:
seo agency 1200 8 --- seo services 800 14 --- technical seo 500 18 ---
🟢 BÀI 11 — FUNCTION
Function = một nhóm lệnh có thể gọi lại.
Ví dụ:
def say_hello(): print("Hello Eric SEO")
Gọi:
say_hello()
19. FUNCTION CHO SEO
Ta tạo:
def classify_keyword(position): if position <= 10: return "TOP 10" elif position <= 20: return "QUICK WIN" else: return "NEED OPTIMIZATION"
Sau đó:
result = classify_keyword(15) print(result)
Kết quả:
QUICK WIN
20. TẠI SAO FUNCTION QUAN TRỌNG?
Thay vì viết:
IF IF IF IF IF IF
ta tạo một function:
classify_keyword()
Sau đó dùng hàng trăm lần.
Đây chính là cách chúng ta xây:
crawl_url() get_gsc_data() analyze_keyword() analyze_content() generate_brief()
sau này.
🚀 PROJECT CUỐI TUẦN
Bây giờ Eric sẽ kết hợp tất cả.
Tạo:
seo_keyword_analyzer.py
Code:
keywords = [ { "keyword": "seo agency", "volume": 1200, "position": 8 }, { "keyword": "seo services", "volume": 800, "position": 14 }, { "keyword": "technical seo", "volume": 500, "position": 18 }, { "keyword": "seo audit", "volume": 300, "position": 32 } ] def classify_keyword(position): if position <= 10: return "TOP 10" elif position <= 20: return "QUICK WIN" elif position <= 50: return "NEED OPTIMIZATION" else: return "LOW PRIORITY" print("=== SEO KEYWORD ANALYZER ===") for item in keywords: keyword = item["keyword"] volume = item["volume"] position = item["position"] status = classify_keyword(position) print( f"{keyword} | " f"Volume: {volume} | " f"Position: {position} | " f"Status: {status}" )
Chạy:
python seo_keyword_analyzer.py
Kết quả:
=== SEO KEYWORD ANALYZER === seo agency | Volume: 1200 | Position: 8 | Status: TOP 10 seo services | Volume: 800 | Position: 14 | Status: QUICK WIN technical seo | Volume: 500 | Position: 18 | Status: QUICK WIN seo audit | Volume: 300 | Position: 32 | Status: NEED OPTIMIZATION
🧠 Eric cần hiểu gì sau Project 01?
Không phải chỉ hiểu đoạn code.
Eric cần nhìn thấy kiến trúc:
DATA ↓ Python ↓ LOGIC ↓ RESULT
Cụ thể:
Keyword data ↓ Dictionary ↓ for ↓ classify_keyword() ↓ if / elif / else ↓ SEO recommendation
Sau này:
GSC API ↓ JSON ↓ Python ↓ AI Agent ↓ SEO Analysis ↓ Recommendation
Đây chính là cầu nối từ Python → API → AI → Agent AI.
📅 Lịch học Tuần 1
| Ngày | Học | Thực hành |
|---|---|---|
| Day 1 | Python, VS Code, print, comment | Hello Eric SEO |
| Day 2 | Variable, String, Number, Boolean | SEO keyword data |
| Day 3 | if, elif, else | Keyword classification |
| Day 4 | List, for | Bulk keyword processing |
| Day 5 | Dictionary | SEO dataset |
| Day 6 | Function | classify_keyword() |
| Day 7 | Tổng hợp | SEO Keyword Analyzer |
⚠️ Một nguyên tắc tôi muốn Eric tuân thủ
Đừng copy đoạn code trên rồi chạy xong báo "đã hiểu".
Hãy làm theo:
Bước 1
Đọc code.
Bước 2
Tự gõ lại.
Bước 3
Chạy.
Bước 4
Cố tình sửa code.
Ví dụ:
position = 8
đổi thành:
position = 15
Rồi:
position = 21
Xem Python thay đổi kết quả như thế nào.
Bước 5
Tự đặt câu hỏi:
"Nếu có 10.000 keyword thì code này có chạy được không?"
Câu trả lời là có — và đó chính là lúc Python bắt đầu có ý nghĩa với SEO.
🎯 BÀI TẬP ERIC LÀM NGAY BÂY GIỜ
Đừng học hết tuần trong một lần.
Hãy bắt đầu Day 1.
Eric mở CMD và chạy:
cd Desktop\seo-agent code .
Sau đó tạo:
week01 └── lesson01.py
Trong lesson01.py, không copy code của tôi ngay, hãy tự viết chương trình hiển thị:
Eric SEO SEO Expert Python AI SEO Agent AI
Sau đó chạy:
python lesson01.py
TUẦN 2 — PYTHON XỬ LÝ DỮ LIỆU SEO
🎯 Mục tiêu cuối tuần
Eric có thể tự làm:
CSV / Excel / JSON ↓ Python ↓ Đọc dữ liệu SEO ↓ Lọc / sắp xếp / tính toán ↓ Phân loại Opportunity ↓ Xuất kết quả
Cuối tuần chúng ta hoàn thành:
Project 02 — Keyword Opportunity Finder
Ví dụ có 1.000 keyword:
keyword volume position seo agency 1200 8 seo services 800 14 technical seo 500 18 seo audit 300 32
Python tự tìm:
QUICK WIN
và ưu tiên theo:
- Position
- Search Volume
- Traffic
- Business value
🛠️ Công cụ sử dụng trong Tuần 2
Eric chỉ cần 3 công cụ:
1. VS Code
Để viết Python.
2. Command Prompt / Terminal
Để chạy Python.
3. Excel hoặc Google Sheets
Để tạo dữ liệu SEO đầu vào.
Chưa cần API. Chưa cần AI.
Chúng ta phải làm chủ dữ liệu trước khi cho AI xử lý dữ liệu.
Cấu trúc thư mục
Trong:
C:\Users\PC\Desktop\seo-agent
tạo:
seo-agent │ ├── week01 │ └── ... │ └── week02 │ ├── lesson01.py ├── lesson02.py ├── lesson03.py ├── lesson04.py ├── lesson05.py ├── lesson06.py │ ├── keywords.csv ├── keywords.json │ └── keyword_opportunity.py
📅 Lịch học Tuần 2
| Ngày | Nội dung | Project |
|---|---|---|
| Day 1 | List nâng cao | SEO keyword database |
| Day 2 | Dictionary nâng cao | SEO records |
| Day 3 | CSV | Import keyword data |
| Day 4 | JSON | Hiểu dữ liệu API |
| Day 5 | Filter + Sort + Calculation | SEO opportunity |
| Day 6 | Pandas cơ bản | Xử lý hàng nghìn keyword |
| Day 7 | Tổng hợp | Keyword Opportunity Finder |
DAY 1 — LIST NÂNG CAO
Tuần 1 Eric đã học:
keywords = [ "seo agency", "seo services", "technical seo" ]
Bây giờ chúng ta phải thao tác với list.
1. len()
len() = đếm số lượng.
Tạo:
week02/lesson01.py
Viết:
keywords = [ "seo agency", "seo services", "technical seo", "seo audit", "seo consultant" ] print(len(keywords))
Chạy:
python lesson01.py
Kết quả:
5
2. Thêm keyword
Dùng:
keywords.append("local seo")
Toàn bộ:
keywords = [ "seo agency", "seo services", "technical seo" ] keywords.append("local seo") print(keywords)
Kết quả:
[ 'seo agency', 'seo services', 'technical seo', 'local seo' ]
Tư duy SEO
Điều này giống như:
Agent phát hiện một keyword mới → thêm vào database.
3. Xóa phần tử
keywords.remove("technical seo")
4. Sắp xếp
keywords.sort()
Python sẽ sắp xếp alphabet.
5. Bài tập Day 1
Tự viết:
keywords = [ "seo", "technical seo", "seo agency", "content seo", "local seo" ]
Sau đó:
- Đếm số keyword.
-
Thêm
"ai seo". -
Xóa
"seo". - Sắp xếp danh sách.
- In danh sách.
Đừng copy đáp án. Tự làm trước.
DAY 2 — DICTIONARY NÂNG CAO
Đây là phần Eric cần đặc biệt hiểu.
Một keyword thực tế không chỉ là một chữ.
Ví dụ:
Keyword: seo agency Volume: 1200 Position: 8 Traffic: 350
Ta lưu:
keyword = { "keyword": "seo agency", "volume": 1200, "position": 8, "traffic": 350 }
6. Lấy dữ liệu
print(keyword["keyword"]) print(keyword["volume"]) print(keyword["position"])
7. Thay đổi dữ liệu
keyword["position"] = 6
Sau đó:
print(keyword)
Position đã thay đổi từ:
8
thành:
6
8. Thêm dữ liệu
Ví dụ thêm:
keyword["intent"] = "commercial"
Bây giờ record có:
keyword volume position traffic intent
9. Nhiều Dictionary trong List
Đây là cấu trúc cực kỳ quan trọng:
keywords = [ { "keyword": "seo agency", "volume": 1200, "position": 8 }, { "keyword": "seo services", "volume": 800, "position": 14 }, { "keyword": "technical seo", "volume": 500, "position": 18 } ]
Hãy ghi nhớ:
List chứa nhiều record. Dictionary chứa thông tin của một record.
10. FOR qua dữ liệu
for item in keywords: print(item["keyword"])
Kết quả:
seo agency seo services technical seo
11. In đẹp hơn
for item in keywords: print( f"{item['keyword']} | " f"Volume: {item['volume']} | " f"Position: {item['position']}" )
Kết quả:
seo agency | Volume: 1200 | Position: 8 seo services | Volume: 800 | Position: 14 technical seo | Volume: 500 | Position: 18
Đây chính là cách chúng ta sẽ xử lý dữ liệu API sau này.
DAY 3 — CSV
Bây giờ chúng ta bỏ dữ liệu ra khỏi Python.
Tạo file:
keywords.csv
Mở bằng Excel và tạo:
| keyword | volume | position | traffic |
|---|---|---|---|
| seo agency | 1200 | 8 | 350 |
| seo services | 800 | 14 | 180 |
| technical seo | 500 | 18 | 100 |
| seo audit | 300 | 32 | 40 |
| local seo | 700 | 6 | 300 |
| ecommerce seo | 400 | 22 | 70 |
| seo consultant | 250 | 12 | 80 |
| seo expert | 600 | 19 | 120 |
Lưu:
week02/keywords.csv
12. Python đọc CSV
Tạo:
lesson03.py
Viết:
import csv with open("keywords.csv", "r", encoding="utf-8") as file: reader = csv.DictReader(file) for row in reader: print(row)
Chạy:
python lesson03.py
Bạn sẽ thấy từng record.
Ví dụ:
{ 'keyword': 'seo agency', 'volume': '1200', 'position': '8', 'traffic': '350' }
⚠️ Một điều rất quan trọng
Eric sẽ thấy:
'1200'
chứ không phải:
1200
Vì CSV đọc dữ liệu vào dưới dạng text/string.
Nếu muốn tính toán:
volume = int(row["volume"])
Tương tự:
position = int(row["position"]) traffic = int(row["traffic"])
13. Lọc keyword Top 20
Bây giờ chúng ta làm việc thật.
import csv with open("keywords.csv", "r", encoding="utf-8") as file: reader = csv.DictReader(file) for row in reader: position = int(row["position"]) if position <= 20: print(row["keyword"])
Kết quả:
seo agency seo services technical seo local seo seo consultant seo expert
🎯 Đây chính là SEO automation.
DAY 4 — JSON
JSON cực kỳ quan trọng vì sau này API trả dữ liệu cho Python thường ở dạng JSON.
Ví dụ:
{ "keyword": "seo agency", "volume": 1200, "position": 8 }
Python đọc JSON.
Tạo:
keywords.json
Nội dung:
[ { "keyword": "seo agency", "volume": 1200, "position": 8 }, { "keyword": "seo services", "volume": 800, "position": 14 }, { "keyword": "technical seo", "volume": 500, "position": 18 } ]
14. Đọc JSON
Tạo:
lesson04.py
import json with open("keywords.json", "r", encoding="utf-8") as file: keywords = json.load(file) for item in keywords: print(item["keyword"])
Chạy:
python lesson04.py
Kết quả:
seo agency seo services technical seo
🧠 Eric cần nhớ điều này
Sau này:
Google Search Console API ↓ JSON ↓ Python
hoặc:
Ahrefs API ↓ JSON ↓ Python
hoặc:
OpenAI API ↓ JSON ↓ Python
Vì vậy:
JSON là một trong những ngôn ngữ dữ liệu quan trọng nhất đối với Agent AI.
DAY 5 — FILTER + SORT + CALCULATION
Bây giờ bắt đầu làm bài toán SEO thật.
15. Tìm Quick Win
Logic:
Position 11–20
Code:
import csv with open("keywords.csv", "r", encoding="utf-8") as file: reader = csv.DictReader(file) for row in reader: position = int(row["position"]) if 11 <= position <= 20: print( row["keyword"], "→ QUICK WIN" )
Kết quả:
seo services → QUICK WIN seo consultant → QUICK WIN seo expert → QUICK WIN
16. Thêm Volume
Chúng ta không chỉ muốn Quick Win.
Chúng ta muốn:
Quick Win + Volume cao
Ví dụ:
if 11 <= position <= 20 and volume >= 500: print("HIGH PRIORITY")
17. Tính Opportunity Score
Ta có thể tạo một điểm đơn giản.
Ví dụ:
Volume càng cao → điểm cao Position càng gần Top 10 → điểm cao
Công thức đơn giản để học Python:
score = volume / position
Ví dụ:
seo services volume = 800 position = 14 score = 800 / 14 ≈ 57.14
18. Python thực hiện
volume = 800 position = 14 score = volume / position print(score)
19. Tư duy quan trọng
Đây là lúc Eric bắt đầu xây:
DATA ↓ FORMULA ↓ DECISION
Sau này Agent sẽ làm:
DATA ↓ AI ANALYSIS ↓ DECISION
DAY 6 — PANDAS
Khi có:
10 keyword
Python thuần đủ dùng.
Nhưng khi có:
10.000 keyword 100.000 keyword 1.000.000 keyword
chúng ta cần pandas.
20. Cài pandas
Trong Terminal:
pip install pandas
Kiểm tra:
python -c "import pandas; print(pandas.__version__)"
Nếu hiện version → thành công.
21. Đọc CSV bằng Pandas
Tạo:
lesson06.py
import pandas as pd df = pd.read_csv("keywords.csv") print(df)
Chạy:
python lesson06.py
Bạn sẽ thấy bảng.
22. Xem 5 dòng đầu
print(df.head())
23. Xem tên cột
print(df.columns)
Kết quả:
Index([ 'keyword', 'volume', 'position', 'traffic' ], dtype='object')
24. Lọc Quick Win
Đây là phần cực kỳ thú vị:
quick_win = df[ (df["position"] >= 11) & (df["position"] <= 20) ] print(quick_win)
Python đã lọc toàn bộ dataset.
25. Quick Win + Volume
opportunity = df[ (df["position"] >= 11) & (df["position"] <= 20) & (df["volume"] >= 500) ] print(opportunity)
Đây chính là:
SEO Keyword Opportunity Finder
phiên bản đầu tiên.
26. Sắp xếp theo Volume
opportunity = opportunity.sort_values( by="volume", ascending=False ) print(opportunity)
Keyword volume cao nhất sẽ lên đầu.
27. Tính Score
df["opportunity_score"] = ( df["volume"] / df["position"] )
Sau đó:
print(df)
Python tự tạo thêm:
opportunity_score
DAY 7 — PROJECT
Bây giờ Eric sẽ xây project hoàn chỉnh.
Tạo:
keyword_opportunity.py
Code:
import pandas as pd # 1. Đọc dữ liệu df = pd.read_csv("keywords.csv") # 2. Tính Opportunity Score df["opportunity_score"] = ( df["volume"] / df["position"] ) # 3. Tìm Quick Win opportunity = df[ (df["position"] >= 11) & (df["position"] <= 20) ] # 4. Sắp xếp opportunity = opportunity.sort_values( by="opportunity_score", ascending=False ) # 5. In kết quả print("=== SEO KEYWORD OPPORTUNITY ===") print( opportunity[ [ "keyword", "volume", "position", "traffic", "opportunity_score" ] ] )
Chạy:
python keyword_opportunity.py
🚀 NÂNG CẤP PROJECT
Bây giờ thêm một cột:
priority
Logic:
Score >= 50 → HIGH Score >= 25 → MEDIUM Còn lại → LOW
Python:
def classify_priority(score): if score >= 50: return "HIGH" elif score >= 25: return "MEDIUM" else: return "LOW"
Sau đó:
df["priority"] = df[ "opportunity_score" ].apply(classify_priority)
In:
print( df[ [ "keyword", "volume", "position", "opportunity_score", "priority" ] ] )
🎯 Thành quả cuối Tuần 2
Eric đã đi từ:
keyword = "seo agency"
đến:
keywords.csv ↓ pandas ↓ lọc 11–20 ↓ tính score ↓ sort ↓ priority
Đây không còn là bài tập Python đơn thuần.
Đây là một SEO automation tool nhỏ.
🔥 Nhưng quan trọng nhất: hãy nhìn về phía trước
Hiện tại:
Nhận xét
Đăng nhận xét