ナビゲーションにスキップ

Can a WeChat article’s province and country help me find local content?

Yes, as a selection clue. province_name and country_name in the wechat_mp.v2.fetch_article_detail_h5 article details describe where the article was published, not where the topic is or where the readers live. To collect articles published in Shanghai, filter saved details by the returned province. To find articles about Shanghai, also review each article’s title and text.

Articles published in Shanghai and articles about Shanghai are different collections. An article published in Beijing about a Shanghai job belongs in a Shanghai hiring shortlist, but not in a sample of Shanghai publications. Decide which of the two geographic questions you are answering before you filter.

Choose evidence for the question

QuestionEvidence
Which province or country is shown as the publication location?The returned article-location fields
Which city, event or job is discussed?Title, text and context
Where does this account’s audience live?Data explicitly defined as reader geography; publication location cannot answer it

Articles from the same account can show different publication locations. Keep each location label in the same row as the article, the source link, the publication time and the collection time.

Filter a saved collection

  1. Reuse the details saved by the article-reading workflow. Read data.content.province_name and data.content.country_name from each data:wechat_mp.v2.fetch_article_detail_h5 result.
  2. Put the returned location labels next to each article link, and add your own topic assessment, such as “Shanghai jobs” or “national industry analysis.”
  3. Filter for the task. For local story ideas, filter by subject relevance first. For a publishing-location review, group by the publication labels. Keep articles with unavailable labels in a separate group.

wechat_mp.v2.fetch_article_detail_h5 retrieves one article by URL, so filter by location after retrieval. Mark empty values as unavailable. When an article’s details are already saved, extract the location fields from the saved details instead of requesting the article again.

For example, an article shows a Beijing publication label, but the article text says the job is in Shanghai. Put Shanghai in “Job location” and Beijing in “Publication label.” Filter job listings by “Job location,” and study where posts were attributed by “Publication label.”

Interpret the location summary

Suppose a selection contains 10 articles: six report Shanghai, two Beijing and two have no province. Write: “Eight of the 10 sampled articles include a publication province; six report Shanghai and two values are unavailable.” Shanghai is 6/8 among reported values, or 6/10 among all observations. Name the denominator in the table header.

The location summary describes the publication labels of the selected articles. It does not provide reader counts or establish that 60% of followers live in Shanghai.

Optional export from saved details

Create locations-input.json with one saved observation per exact requested article URL. Record the requested link, collection time and response file:

[{"url":"https://mp.weixin.qq.com/s/REPLACE_WITH_REAL_ARTICLE","collected_at":"2026-11-16T10:00:00Z","file":"article-1/wechat-article.json"}]

Save the Python script below as publication_locations.py and run python3 publication_locations.py locations-input.json location-review. publication_locations.py accepts 1–50 observations and creates publication-locations.csv, exact-value JSON, coverage.json and copies of the original responses. The script stops instead of overwriting an existing output directory.

import collections,csv,hashlib,json,pathlib,sys
from datetime import datetime
from urllib.parse import parse_qs,urlsplit
manifest,out=map(pathlib.Path,sys.argv[1:3]);manifest_bytes=manifest.read_bytes();entries=json.loads(manifest_bytes)
if not isinstance(entries,list) or not 1<=len(entries)<=50:raise ValueError('Supply 1-50 saved observations')
def article_url(value):
if not isinstance(value,str):raise ValueError('Expected requested article URL')
u=urlsplit(value)
if u.scheme!='https' or u.hostname!='mp.weixin.qq.com' or u.username is not None or u.password is not None or u.port not in (None,443):raise ValueError('Expected HTTPS WeChat article')
if u.path=='/s':
q=parse_qs(u.query,keep_blank_values=True)
if not all(len(q.get(k,[]))==1 and q[k][0].strip() for k in ('__biz','mid','idx')):raise ValueError('Long URL lacks article identity')
if not q['mid'][0].isascii() or not q['mid'][0].isdigit() or not q['idx'][0].isascii() or not q['idx'][0].isdigit() or int(q['idx'][0])<1:raise ValueError('Bad article position')
elif not u.path.startswith('/s/') or not u.path[3:] or '/' in u.path[3:]:raise ValueError('Expected article path')
return value
def field(content,key):
if key not in content:return None,'absent'
value=content[key]
if value is None:return None,'null'
if not isinstance(value,str):raise ValueError('Location must be a string or missing')
return value,('reported' if value.strip() else 'empty')
rows=[];raws=[];seen_requests=set();seen_urls=set();countries=collections.Counter();provinces=collections.Counter()
for n,entry in enumerate(entries,1):
url=article_url(entry['url']);stamp=datetime.fromisoformat(entry['collected_at'].replace('Z','+00:00'))
if stamp.utcoffset() is None:raise ValueError('Collection time needs a timezone')
if url in seen_urls:raise ValueError('Choose one observation per exact requested URL')
seen_urls.add(url);path=manifest.parent/entry['file'];raw=path.read_bytes();r=json.loads(raw)
if not isinstance(r,dict) or r.get('status')!='succeeded' or r.get('action')!='wechat_mp.v2.fetch_article_detail_h5' or r.get('error') is not None:raise ValueError('Expected successful article detail')
rid=r.get('request_id');data=r.get('data')
if not isinstance(rid,str) or not rid.strip() or rid in seen_requests or not isinstance(data,dict) or not isinstance(data.get('content'),dict):raise ValueError('Missing/repeated provenance or content')
seen_requests.add(rid)
if data.get('url') is not None and data['url']!=url:raise ValueError('Response request URL differs')
content=data['content'];country,cs=field(content,'country_name');province,ps=field(content,'province_name')
if cs=='reported':countries[country]+=1
if ps=='reported':provinces[(country if cs=='reported' else None,province)]+=1
row={'requested_url':url,'collected_at':entry['collected_at'],'country_name':country,'country_state':cs,'province_name':province,'province_state':ps,'request_id':rid,'request_url_echo_verified':data.get('url')==url,'source_sha256':hashlib.sha256(raw).hexdigest(),'source_file':str(path.resolve()),'archive_file':'raw-%02d.json'%n}
rows.append(row);raws.append(raw)
def safe(v):
if v is None:return ''
s=str(v)
return "'"+s if s.lstrip().startswith(('=','+','-','@')) or s.startswith(('\t','\r','\n')) else s
report={'saved_observations':len(rows),'unique_request_urls':len(seen_urls),'url_aliases_resolved':False,'country_states':dict(collections.Counter(x['country_state'] for x in rows)),'province_states':dict(collections.Counter(x['province_state'] for x in rows)),'countries':[{'country_name':k,'observations':v} for k,v in sorted(countries.items())],'province_groups':[{'country_name':k[0],'province_name':k[1],'observations':v} for k,v in sorted(provinces.items(),key=lambda item:json.dumps(item[0],ensure_ascii=False))],'manifest_sha256':hashlib.sha256(manifest_bytes).hexdigest(),'scope':'Selected saved article observations; not readers, unique authors, account addresses or audience geography'}
out.mkdir();(out/'manifest.json').write_bytes(manifest_bytes)
for row,raw in zip(rows,raws):(out/row['archive_file']).write_bytes(raw)
with (out/'publication-locations.csv').open('x',encoding='utf-8-sig',newline='') as f:
w=csv.DictWriter(f,fieldnames=list(rows[0]));w.writeheader();w.writerows({k:safe(v) for k,v in row.items()} for row in rows)
(out/'publication-locations.json').write_text(json.dumps(rows,ensure_ascii=False,indent=2),encoding='utf-8')
(out/'coverage.json').write_text(json.dumps(report,ensure_ascii=False,indent=2),encoding='utf-8')
print(str(out))

Filter in the CSV file and read exact values in the JSON file. Missing fields, null, empty strings and reported labels stay distinct. Counts use saved_observations, and the script does not merge a short URL with the long URL of the same article, so check for short/long URL aliases when you select the collection. The script does not infer a missing country from the province.

For the price of new detail requests, see the current pricing page. Local extraction and grouping reuse saved results and make no new requests.

WeChat questions