可以通过一点 Python 编码来实现。
我编写了一个简单的脚本来获取货运办公室的位置。
第一步
- 例如,用谷歌浏览器打开 ajax 页面,用土耳其语,但你可以理解它。
http://www.yurticikargo.com/bilgi-servisleri/Sayfalar/en-yakin-sube.aspx
- 按 F12 显示底部开发人员工具并导航到网络选项卡。
- 导航底部的XHR选项卡。
- 通过在第一个组合框中选择一个项目来发出 AJAX 请求。并转到标题选项卡
您将GetTownByCity在左窗格中,单击它并检查它。
Request URL: (...)/_layouts/ArikanliHolding.YurticiKargo.WebSite/ajaxproxy-
sswservices.aspx/GetTownByCity
Request Method:POST
Status Code:200 OK
在Request Payload
树项目中,您将看到
Request Payload :{cityId:34}
标题。
这将指导我们实现 python 代码。
我们开始做吧。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
# import simplejson as json
baseUrl = 'http://www.yurticikargo.com/'
ajaxRoot = '_layouts/ArikanliHolding.YurticiKargo.WebSite/'
getTown = 'ajaxproxy-sswservices.aspx/GetTownByCity'
urlGetTown = baseUrl + ajaxRoot + getTown
headers = {'content-type': 'application/json','encoding':'utf-8'} # We are sending JSON headers, equivalent to Python dictionary
for plaka in range(1,82): # Because Turkiye has number plates from 1 to 81
payload = {'cityId':plaka}
r = requests.post(url, data=json.dumps(payload), headers=headers)
data = r.json() # Returning data is in JSON format, if you need HTML use r.content()
# ... Process the fetched data with JSON parser,
# If HTML format, Beautiful Soup, Lxml, or etc...
请注意,此代码是我工作代码的一部分,它是即时编写的,最重要的是我没有测试它。它可能需要进行一些小的修改才能运行它。