程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python series 34: crawling Ajax requests in Python

編輯:Python

1. see ajax The real address to send the request

Use F12 open chrome Developer interface for , Then execute the page again , We can see that :

Click the one with the longest execution time ajax request , We can see the real request (headers in ) And parameters (payload in ) 了 :

2. Request code

url:Header Medium request url
headers:Header Medium request headers
params:Payload Medium Query String Parameters
data:Payload Medium From Data
Compare the two pictures above , The code for crawling page information is as follows :

import requests
from tqdm import tqdm
headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.115 Safari/537.36',
'Referer': 'https://www.jst-purple.com.cn/purple/index.php',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'PHPSESSID=tr0n497tu1oslsnpgct8n03261'}
url = "https://www.jst-purple.com.cn/purple/ajax_show_search_product.php"
params = {'callback':'jQuery1111007706371456432315_1655294131309'}
# Here we usually use multithreading to crawl web pages
for i in tqdm(range(1,248)):
rep=requests.post(url=url,params=params,data={"current_page":i},headers=headers)
html = rep.text...

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved