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

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()

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章