Zzzxb's Blog

你要静心学习那份等待时机的成熟的情绪,也要你一定保有这份等待之外的努力和坚持。

CURL访问百度搜索问题 Feb 27, 2026

curl

curl -L \
  -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" \
  -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
  -H "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8" \
  -H "Accept-Encoding: gzip" \
  -H "Referer: https://www.baidu.com/" \
  -H "Connection: keep-alive" \
  --compressed \
  "https://www.baidu.com/s?wd=通天购"

wget

wget \
  -U "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" \
  --header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
  --header="Accept-Language: zh-CN,zh;q=0.9,en;q=0.8" \
  --header="Accept-Encoding: gzip" \
  --header="Referer: https://www.baidu.com/" \
  --header="Connection: keep-alive" \
  -O baidu_result.html \
  "https://www.baidu.com/s?wd=通天购"

Python

import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Accept-Encoding': 'gzip',
    'Referer': 'https://www.baidu.com/',
    'Connection': 'keep-alive',
}

url = 'https://www.baidu.com/s?wd=%E9%80%9A%E5%A4%A9%E8%B4%AD'

response = requests.get(url, headers=headers)
print(response.text[:1000])  # 打印前1000字符