How to Scrape Japanese Websites Correctly: Encodings, Text and Polite Crawling
By the ProxyV4 Engineering Team · Updated:
To scrape Japanese websites correctly, decode each page with the encoding it actually uses (UTF-8, Shift_JIS or EUC-JP), normalize full-width characters before you parse numbers, and collect only public data at a polite pace after checking robots.txt and the site's terms. Most garbled output (mojibake) comes from decoding Shift_JIS or EUC-JP as UTF-8 or Latin-1. This guide explains the Japanese specifics and gives a runnable Python example that handles them.
What makes it different to scrape Japanese websites
Three things trip up crawlers built for English sites. First, encodings: modern Japanese sites mostly use UTF-8, but many older shops, forums, government pages and long-running catalogs still serve Shift_JIS (often really Windows-31J, also called CP932) or EUC-JP. Second, text: Japanese mixes full-width and half-width characters, so the price ¥1,980 and ¥1,980 are the same number written two ways. Third, rules: Japanese copyright and personal data law apply to what you collect and keep.
None of this needs a special framework. It needs careful decoding, a normalization step and a crawler that behaves well.
Decoding Shift_JIS and EUC-JP in Python
Python's requests guesses response.text from the HTTP header. When a Japanese server sends text/html without a charset, the guess can be wrong, and you get mojibake. The fix is to decode response.content (raw bytes) yourself:
- Read the charset from the header, then from the
<meta charset>tag in the first few kilobytes if the header has none. - Map Shift_JIS names to `cp932`. Sites labelled Shift_JIS often use Windows extensions such as circled numbers (①) and some kanji that strict
shift_jiscannot decode;cp932handles them. - Use `euc_jp` for EUC-JP pages. It is common on older Unix-built sites and some long-running services.
- Decode with `errors="replace"` so one bad byte does not crash a run, and log pages where replacements appear.
When the declared encoding is wrong
Sometimes a page declares one encoding and uses another, often after a CMS migration or on pages assembled from older templates. A quick test catches it: count the replacement characters (U+FFFD) after decoding. If a page labelled UTF-8 is full of them, try cp932 and euc_jp on the same bytes and keep the result with the fewest replacements. Log those URLs, because the same template usually affects a whole section of the site.
Normalizing full-width text
After decoding, run unicodedata.normalize("NFKC", text) on fields you parse. NFKC turns full-width digits and letters (123, ABC) into ASCII and half-width katakana into full-width katakana, so prices, model numbers and postal codes compare correctly. Keep the original text too if you display it, because NFKC also changes some symbols.
Japanese numbers, prices and dates
Consumer prices in Japan are shown including consumption tax (総額表示), sometimes with the pre-tax amount alongside as 税抜. Large amounts can use 万 (10,000), as in 1.5万円. Dates may use the Japanese era (令和7年 is 2025). Write explicit parsers for these instead of hoping a generic library guesses.
A runnable Japanese scraper in Python
The example below fetches a short list of pages through a Japanese proxy. It checks robots.txt with the same session, detects Shift_JIS or EUC-JP from the header or meta tag, decodes the raw bytes, normalizes the title with NFKC, stops on 403, 429 or 503 instead of retrying harder, and waits between requests. All requests have timeouts.
# pip install requests beautifulsoup4
import codecs, re, time, unicodedata
from urllib.parse import urljoin, urlsplit
from urllib.robotparser import RobotFileParser
import requests
from bs4 import BeautifulSoup
PROXY = "http://USER:PASS@IP:PORT"
S = requests.Session()
S.proxies = {"http": PROXY, "https": PROXY}
S.headers.update({"User-Agent": "example-research-bot/1.0 ([email protected])",
"Accept-Language": "ja,en;q=0.5"})
SJIS = {"shift_jis", "shift-jis", "sjis", "x-sjis", "windows-31j", "ms_kanji", "cp932"}
EUC = {"euc-jp", "eucjp", "x-euc-jp", "euc_jp"}
def page_encoding(resp):
m = re.search(r"charset=[\"']?([\w-]+)", resp.headers.get("Content-Type", ""), re.I)
name = m.group(1) if m else None
if not name:
m = re.search(rb"<meta[^>]+charset=[\"']?([\w-]+)", resp.content[:4096], re.I)
name = m.group(1).decode("ascii") if m else "utf-8"
name = name.lower()
if name in SJIS:
return "cp932" # Windows-31J: superset of Shift_JIS used by most sites
if name in EUC:
return "euc_jp"
try:
return codecs.lookup(name).name
except LookupError:
return "utf-8"
def allowed(url):
root = "{0.scheme}://{0.netloc}".format(urlsplit(url))
rp = RobotFileParser()
r = S.get(urljoin(root, "/robots.txt"), timeout=15)
rp.parse(r.text.splitlines() if r.ok else [])
return rp.can_fetch(S.headers["User-Agent"], url)
def fetch(url):
if not allowed(url):
print("robots.txt disallows", url); return None
r = S.get(url, timeout=(10, 30))
if r.status_code in (403, 429, 503):
print("server asked us to stop:", r.status_code); return None
r.raise_for_status()
html = r.content.decode(page_encoding(r), errors="replace")
soup = BeautifulSoup(html, "html.parser")
title = soup.title.get_text(strip=True) if soup.title else ""
return unicodedata.normalize("NFKC", title) # full-width -> half-width digits
for url in ["https://www.example.jp/catalog/1", "https://www.example.jp/catalog/2"]:
print(url, fetch(url))
time.sleep(10) # polite paceReplace the example URLs with pages you are allowed to collect, and set a real contact address in the User-Agent so site owners can reach you. The Python requests proxy guide covers proxy syntax and SOCKS5 variants.
Polite crawling and Japanese law
Check for an official API or data feed first; many Japanese services, from e-commerce platforms to public agencies, publish one. If you crawl, keep the rate low, honor robots.txt and the site's terms, cache what you have already fetched, and stop when the server tells you to. Never answer a 429 or a block by switching IPs.
Japan's Copyright Act includes provisions on using works for information analysis, but they have limits and conditions, and they do not override a site's terms or other laws. The Act on the Protection of Personal Information (APPI) covers names, contact details and other personal data, so leave them out unless you have a lawful basis. Japan's Unauthorized Computer Access law prohibits getting around access controls such as logins. This is general information, not legal advice; for a broader view see is web scraping with proxies legal.
When a Japanese IP fits your crawler, and when it does not
Some Japanese sites show different content, prices or stock to visitors in Japan, or serve their domestic catalog only to Japanese addresses. For a polite, scheduled crawl of that public content, a fixed Japanese IP keeps results consistent. ProxyV4 sells private Japan IPv4 proxies: private datacenter IPv4 addresses in Japan, one tenant per IP for the whole term, the same IP while active and on renewal before expiry.
Every proxy supports HTTP(S) and SOCKS5, with username and password login by default; IP whitelist login is also offered on the order page for up to 3 public IPv4 addresses, which suits a crawler server. Traffic is unmetered, so you pay per IP per month in USD rather than per gigabyte, with 1, 3, 12 or custom terms and lower per-IP prices at higher quantities. See live prices and start with a single IP.
Where it does not fit: a datacenter IP is not a way to get past rate limits, CAPTCHAs or blocks, and ProxyV4 does not sell rotating pools for that. If a site does not want to be crawled, the answer is its API or permission, not more IPs. In Japan, ProxyV4 sells private datacenter IPv4 and static ISP. For the broader use case, see web scraping proxies and the Japan proxy page.
Frequently asked questions
How do I decode Shift_JIS in Python?
Decode the raw bytes with response.content.decode("cp932", errors="replace"). CP932 covers the Windows extensions most Shift_JIS sites use.
How do I handle EUC-JP with requests?
Detect the charset from the header or meta tag and decode response.content with euc_jp instead of trusting response.text.
Why do Japanese numbers fail to parse?
They are often full-width characters. Normalize with NFKC before parsing, and handle 万 and era dates explicitly.
Should I switch IPs when a Japanese site returns 429?
No. A 429 means slow down. Back off, reduce the rate, or ask the site for API access.
Does crawling cost extra traffic fees on ProxyV4?
No. Traffic on private IPv4 is unmetered; you pay per IP per month.
Sources
- Copyright Act (Act No. 48 of 1970), Japanese Law Translation
- Act on the Protection of Personal Information (Act No. 57 of 2003), Japanese Law Translation
- Act on Prohibition of Unauthorized Computer Access (Act No. 128 of 1999), Japanese Law Translation
- Personal Information Protection Commission, Japan: Laws and Policies
Japanese IPv4 with unmetered traffic for polite crawls
Run scheduled, polite crawls of public Japanese pages from one private Japan IPv4 address. HTTP(S) and SOCKS5, the same IP on renewal, no per-GB billing.
See Japan prices