<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lưu trữ scraping website - Tenten AI</title>
	<atom:link href="https://tenten.vn/ai/tag/scraping-website/feed/" rel="self" type="application/rss+xml" />
	<link>https://tenten.vn/ai/tag/scraping-website/</link>
	<description>Chia sẻ kiến thức về AI</description>
	<lastBuildDate>Wed, 12 Mar 2025 04:07:49 +0000</lastBuildDate>
	<language>vi</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://tenten.vn/ai/wp-content/uploads/2022/09/cropped-skyperry-32x32.png</url>
	<title>Lưu trữ scraping website - Tenten AI</title>
	<link>https://tenten.vn/ai/tag/scraping-website/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Cách lấy dữ liệu trang web trong 1 nốt nhạc mà không cần biết code</title>
		<link>https://tenten.vn/ai/cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code/</link>
		
		<dc:creator><![CDATA[Quản trị viên]]></dc:creator>
		<pubDate>Wed, 12 Mar 2025 04:07:49 +0000</pubDate>
				<category><![CDATA[ChatGPT]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[lấy dữ liệu]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[scraping website]]></category>
		<guid isPermaLink="false">https://tenten.vn/ai/?p=11649</guid>

					<description><![CDATA[<p>Chắc hẳn nhiều bạn lấy dữ liệu đều gặp phải trường hợp phổ biến này. Không API, không thể truy cập cơ sở dữ liệu, và một trang web với &#8220;bức tường&#8221; bảo vệ như là: reCAPTCHA khó nhằn, ngăn chặn địa lý, giới hạn yêu cầu theo thời gian, và cấu trúc HTML được &#8230;</p>
<p>Bài viết <a href="https://tenten.vn/ai/cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code/">Cách lấy dữ liệu trang web trong 1 nốt nhạc mà không cần biết code</a> đã xuất hiện đầu tiên vào ngày <a href="https://tenten.vn/ai">Tenten AI</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span style="font-weight: 400;">Chắc hẳn nhiều bạn lấy dữ liệu đều gặp phải trường hợp phổ biến này. Không API, không thể truy cập cơ sở dữ liệu, và một trang web với &#8220;bức tường&#8221; bảo vệ như là: reCAPTCHA khó nhằn, ngăn chặn địa lý, giới hạn yêu cầu theo thời gian, và cấu trúc HTML được thiết kế để chống lại bạn. Trong bài viết này, </span><a href="https://tenten.vn/vi"><span style="font-weight: 400;">Tenten.vn</span></a><span style="font-weight: 400;"> sẽ chia sẻ với bạn cách vượt qua những trở ngại tưởng chừng không thể ấy. Bạn không cần phải là một người biết nhiều ngôn ngữ lập trình nhưng vẫn xử lý được. Hãy cùng khám phá nhé!</span></p>
<h2><b>Vượt qua reCAPTCHA và phát hiện bot</b></h2>
<p><span style="font-weight: 400;">Nhiều trang web hiện đại sử dụng </span><a href="https://tenten.vn/tin-tuc/recaptcha-la-gi/"><span style="font-weight: 400;">reCAPTCHA</span></a><span style="font-weight: 400;"> để ngăn chặn các bot tự động. Công cụ này không chỉ để kiểm tra bot, mà còn phân tích rất kỹ các hành vi của bạn:</span></p>
<ul>
<li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Chuyển động chuột: Nếu chuột di chuyển theo đường thẳng hoặc quá đều đặn, hệ thống sẽ nghi ngờ bot.</span></li>
<li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">User Agent giả mạo: Các trình duyệt giả lập thường sử dụng User Agent không hợp lệ, dễ bị phát hiện.</span></li>
<li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Tốc độ tương tác: Nếu bạn gửi yêu cầu quá nhanh hoặc quá nhiều trong thời gian ngắn, hệ thống sẽ coi đó là dấu hiệu của bot.</span></li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-11650 size-full" src="https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-1.jpg" alt="Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-1" width="600" height="338" srcset="https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-1.jpg 600w, https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-1-300x169.jpg 300w, https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-1-390x220.jpg 390w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p>Và để vượt qua các công cụ ngăn chặn bot, chúng ta có<b> Puppeteer</b><span>. Nór cho phép bạn mô phỏng hành vi của một người dùng thực sự, từ việc di chuyển chuột ngẫu nhiên, thiết lập User Agent hợp lệ, đến việc giải quyết reCAPTCHA thủ công.</span></p>
<p><span style="font-weight: 400;">Dưới đây là một đoạn mã nguồn (JavaScript) đơn giản sử dụng Puppeteer để vượt qua reCAPTCHA và truy cập dữ liệu:</span></p>
<p><code><span style="font-weight: 400;">const puppeteer = require('puppeteer');</span></code></p>
<p><code><span style="font-weight: 400;">async function bypassCaptcha() {</span></code></p>
<p><code><span style="font-weight: 400;">  // Khởi tạo trình duyệt (chạy ở chế độ hiển thị để dễ quan sát)</span></code></p>
<p><code><span style="font-weight: 400;">  const browser = await puppeteer.launch({ headless: false });</span></code></p>
<p><code><span style="font-weight: 400;">  const page = await browser.newPage();</span></code></p>
<p><code><span style="font-weight: 400;">  // Thiết lập User Agent hợp lệ để giả lập trình duyệt thật</span></code></p>
<p><code><span style="font-weight: 400;">  await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');</span></code></p>
<p><code><span style="font-weight: 400;">  // Tạo chuyển động chuột ngẫu nhiên để qua mặt reCAPTCHA</span></code></p>
<p><code><span style="font-weight: 400;">  await page.mouse.move(100 + Math.random() * 500, 200 + Math.random() * 300);</span></code></p>
<p><code><span style="font-weight: 400;">  // Truy cập trang web mục tiêu</span></code></p>
<p><code><span style="font-weight: 400;">  await page.goto('https://example.com');</span></code></p>
<p><code><span style="font-weight: 400;">  // Đóng trình duyệt sau khi hoàn thành</span></code></p>
<p><code><span style="font-weight: 400;">  await browser.close();</span></code></p>
<p><code><span style="font-weight: 400;">}</span></code></p>
<p><b>Cách sử dụng đoạn mã:</b><span style="font-weight: 400;"> Mở bất kỳ trình soạn thảo văn bản nào (như Visual Studio Code, Sublime Text, hoặc Notepad++), dán đoạn mã nguồn và lưu tên thành tên bất kỳ ví dụ là <em>inedex.js</em>. Sau khi đã lưu file <em>index.js</em>, quay lại Terminal hoặc Command Prompt, chạy lệnh sau:</span></p>
<p><code><span style="font-weight: 400;">node index.js</span></code></p>
<p><span style="font-weight: 400;">Nếu mọi thứ được thiết lập đúng, Puppeteer sẽ khởi chạy một cửa sổ trình duyệt, thực hiện các hành động như di chuyển chuột ngẫu nhiên và truy cập trang web mà bạn đã chỉ định.</span></p>
<h2><b>Khắc phục chặn địa lý và giới hạn tốc độ</b></h2>
<p><span style="font-weight: 400;">Có đôi lúc, bạn không thể truy cập 1 trang web hoặc bị chặn sau vài lần tải trang. Đó là họ chặn IP từ các khu vực cụ thể hoặc giới hạn số lượng yêu cầu (ví dụ: chỉ cho phép 5 lần truy cập trong 10 phút).</span></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-11651 size-full" src="https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-2.jpg" alt="Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-2" width="600" height="350" srcset="https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-2.jpg 600w, https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-2-300x175.jpg 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p><span style="font-weight: 400;">Để vượt qua chặn IP địa lý và giới hạn tốc độ, bạn có thể sử dụng </span><a href="https://smartproxy.com/blog/why-rotating-proxies-are-the-best#:~:text=A%20rotating%20proxy%20is%20a%20proxy%20server%20that%20automatically%20switches,a%20different%20device%20or%20location."><b>rotating residential proxies</b></a><span style="font-weight: 400;">. Đây là những proxy mô phỏng lưu lượng truy cập từ các địa chỉ IP thực của người dùng tại các khu vực cụ thể. Bằng cách thay đổi IP sau mỗi vài yêu cầu, bạn có thể tránh bị phát hiện và ngăn chặn.</span></p>
<p><span style="font-weight: 400;">Dưới đây là một đoạn mã nguồn Python đơn giản sử dụng </span><span style="font-weight: 400;">rotating residential proxies</span><span style="font-weight: 400;">. để khắc phục vấn đề này:</span></p>
<p><code><span style="font-weight: 400;">import requests</span></code></p>
<p><code><span style="font-weight: 400;">from time import sleep</span></code></p>
<p><code><span style="font-weight: 400;"># </span><span style="font-weight: 400;">rotating residential proxies</span><span style="font-weight: 400;"> (thay thế bằng proxy thực tế của bạn)</span></code></p>
<p><code><span style="font-weight: 400;">proxy_list = [</span></code></p>
<p><code><span style="font-weight: 400;">    "http://user:pass@br.proxy.example.com:8080",</span></code></p>
<p><code><span style="font-weight: 400;">    "http://user:pass@us.proxy.example.com:8080",</span></code></p>
<p><code><span style="font-weight: 400;">    # Thêm các proxy khác vào đây...</span></code></p>
<p><code><span style="font-weight: 400;">]</span></code></p>
<p><code><span style="font-weight: 400;">def scrape_safe(url):</span></code></p>
<p><code><span style="font-weight: 400;">    for proxy in proxy_list:</span></code></p>
<p><code><span style="font-weight: 400;">        try:</span></code></p>
<p><code><span style="font-weight: 400;">            # Gửi yêu cầu với proxy hiện tại</span></code></p>
<p><code><span style="font-weight: 400;">            response = requests.get(url, proxies={"http": proxy, "https": proxy})</span></code></p>
<p><code><span style="font-weight: 400;">            if response.status_code == 200:</span></code></p>
<p><code><span style="font-weight: 400;">                return response.text  # Trả về nội dung trang web nếu thành công</span></code></p>
<p><code><span style="font-weight: 400;">            sleep(10)  # Thêm độ trễ 10 giây giữa các yêu cầu</span></code></p>
<p><code><span style="font-weight: 400;">        except Exception as e:</span></code></p>
<p><code><span style="font-weight: 400;">            print(f"Lỗi với proxy {proxy}: {e}")</span></code></p>
<p><code><span style="font-weight: 400;">            continue  # Chuyển sang proxy tiếp theo nếu lỗi xảy ra</span></code></p>
<p><code><span style="font-weight: 400;">    return None  # Trả về None nếu tất cả proxy đều thất bại</span></code></p>
<p><b>Cách sử dụng đoạn mã:</b><span style="font-weight: 400;"> Mở bất kỳ trình soạn thảo văn bản nào (như Visual Studio Code, Sublime Text, hoặc Notepad++), dán đoạn mã nguồn và lưu tên thành tên bất kỳ </span><i><span style="font-weight: 400;">ví dụ Scraping.py</span></i><span style="font-weight: 400;">. Quay lại Terminal hoặc Command Prompt, đảm bảo bạn đang ở trong thư mục chứa file <em>scrape.py,</em> và chạy lệnh sau:</span></p>
<p><code>python scrape.py</code></p>
<h2><b>Xử lý HTML phi cấu trúc</b></h2>
<p><span style="font-weight: 400;">Nhiều trang web hiện đại sử dụng các framework như React, Angular, hoặc Vue.js, khiến cấu trúc HTML có thể thay đổi linh hoạt và làm khó bạn lấy dữ liệu. Ví dụ, một danh sách sản phẩm hôm nay nằm trong thẻ </span><code><span style="font-weight: 400;">&lt;div class="product-list"&gt;</span></code><span style="font-weight: 400;">, nhưng ngày mai lại chuyển sang </span><code><span style="font-weight: 400;">&lt;section id="products"&gt;</span></code><span style="font-weight: 400;">.</span></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-11652 size-full" src="https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-3.jpg" alt="Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-3" width="600" height="300" srcset="https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-3.jpg 600w, https://tenten.vn/ai/wp-content/uploads/2025/03/Cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code-3-300x150.jpg 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p><span style="font-weight: 400;">Để vượt qua, chúng ta có thể sử dụng </span><a href="https://github.com/unclecode/crawl4ai"><b>Crawl4AI</b></a><span style="font-weight: 400;"> – một công cụ mạnh mẽ kết hợp giữa thu thập dữ liệu và trí tuệ nhân tạo cùng với mô hình ngôn ngữ </span><b>DeepSeek</b><span style="font-weight: 400;">. Thay vì phụ thuộc vào cấu trúc HTML cố định, giải pháp này tập trung vào ý nghĩa của dữ liệu, giúp bạn trích xuất thông tin linh hoạt.</span></p>
<p><span style="font-weight: 400;">Dưới đây là một đoạn mã Python đơn giản sử dụng Crawl4AI và DeepSeek để xử lý HTML phi cấu trúc:</span></p>
<p><code><span style="font-weight: 400;">from crawl4ai import WebCrawler</span></code></p>
<p><code><span style="font-weight: 400;">from llama_cpp import Llama</span></code></p>
<p><code><span style="font-weight: 400;"># Khởi tạo mô hình ngôn ngữ DeepSeek</span></code></p>
<p><code><span style="font-weight: 400;">llm = Llama(model_path="deepseek-1.3b.gguf")</span></code></p>
<p><code><span style="font-weight: 400;"># Khởi tạo WebCrawler</span></code></p>
<p><code><span style="font-weight: 400;">crawler = WebCrawler()</span></code></p>
<p><code><span style="font-weight: 400;"># Chạy quá trình cào dữ liệu với chiến lược sử dụng LLM</span></code></p>
<p><code><span style="font-weight: 400;">content = crawler.run(</span></code></p>
<p><code><span style="font-weight: 400;">    url="https://example.com",</span></code></p>
<p><code><span style="font-weight: 400;">    strategy="llm",  # Sử dụng chiến lược dựa trên LLM</span></code></p>
<p><code><span style="font-weight: 400;">    llm=llm,</span></code></p>
<p><code><span style="font-weight: 400;">    prompt="Extract product names, prices into JSON"</span></code></p>
<p><code><span style="font-weight: 400;">)</span></code></p>
<p><code><span style="font-weight: 400;"># In ra dữ liệu đã trích xuất</span></code></p>
<p><code><span style="font-weight: 400;">print(content.extracted_data)</span></code></p>
<p><b>Cách sử dụng đoạn mã:</b><span style="font-weight: 400;"> Mở bất kỳ trình soạn thảo văn bản nào (như Visual Studio Code, Sublime Text, hoặc Notepad++), dán đoạn mã nguồn và lưu tên thành tên bất kỳ </span><i><span style="font-weight: 400;">ví dụ crawler.py</span></i><span style="font-weight: 400;">. Quay lại Terminal hoặc Command Prompt, đảm bảo bạn đang ở trong thư mục chứa file <em>scrape.py</em>, và chạy lệnh sau:</span></p>
<p><code><span style="font-weight: 400;">python crawler.py</span></code></p>
<h2><b>Kết Luận</b></h2>
<p><span style="font-weight: 400;">Qua bài, chúng ta đã  khám phá cách vượt qua những rào cản phổ biến khi lấy dữ liệu từ các trang web. Hãy nhớ rằng, việc lấy dữ liệu cần tuân thủ các quy định và chính sách của trang web. Hãy luôn đảm bảo rằng bạn sử dụng dữ liệu một cách hợp pháp và đạo đức, tránh gây ảnh hưởng tiêu cực đến hệ thống hoặc trải nghiệm của người dùng khác.</span></p>
<p><span style="font-weight: 400;">Nếu bạn có bất kỳ khó khăn trong quá trình thực hiện, hãy để lại lời nhắn để chúng tôi giúp bạn!</span></p>
<p>Bài viết <a href="https://tenten.vn/ai/cach-lay-du-lieu-trang-web-trong-1-not-nhac-ma-khong-can-biet-code/">Cách lấy dữ liệu trang web trong 1 nốt nhạc mà không cần biết code</a> đã xuất hiện đầu tiên vào ngày <a href="https://tenten.vn/ai">Tenten AI</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
