python 抓接口 利用requests 增加 headers示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import requests;
from bs4 import BeautifulSoup
   
# instance of Options class allows
# us to configure Headless Chrome
options = Options()
   
# this parameter tells Chrome that
# it should be run without UI (Headless)
options.headless = True
 
 
 
# initializing webdriver for Chrome with our options
driver = webdriver.Chrome(options=options)
 
  
url = "https://lbs.xx.com/_AMapService/v3/place/text?s=rsv3&children=&key=f7d40927ba4d64fb91ebe2bb9cda0995&offset=1&page=1&extensions=all&city=110000&language=zh_cn&callback=jsonp_415841_&platform=JS&logversion=2.0&appname=https://lbs.amap.com/tools/picker&csid=5E26AB3D-3D05-42F3-8D9A-931F510D3197&sdkversion=1.4.20&keywords=大郊亭 盒马"
  
headers = {
'accept':'*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'cookie': 'cna=7akMGzUanzICAbYzVjw6oJRX; AMAPID=27.',
 
'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36 Edg/107.0.1418.35'
}
 
result = requests.get(url, headers=headers)
   
# We can also get some information
# about page in browser.xq
# So let's output webpage title into
# terminal to be sure that the browser
# is actually running.
print(BeautifulSoup(result.content))
   
# close browser after our manipulations
driver.close()

  

posted @   iDEAAM  阅读(350)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
点击右上角即可分享
微信分享提示