Shell 如何从URL获取特定内容
我想用不同的跟踪号递归地点击下面的URL,并从URL中仅获取装运状态 UPS URL: 我尝试了wget命令,但它无法加载整个文件,而且它对我没有任何用处,curl在我的系统中也不起作用Shell 如何从URL获取特定内容,shell,unix,wget,Shell,Unix,Wget,我想用不同的跟踪号递归地点击下面的URL,并从URL中仅获取装运状态 UPS URL: 我尝试了wget命令,但它无法加载整个文件,而且它对我没有任何用处,curl在我的系统中也不起作用 wget--无检查证书--输出文档ttt.htm“$UPS\u URL” 任何其他解决方法都会非常有用。您使用了错误的页面和请求方法来获取数据。我访问了您链接到的页面,它只包含一个文本框,您可以在其中添加装运编号,然后将您重定向到包含结果的页面 因此,在此页面上简单地调用Wget将不会起任何作用。您需要知道要
wget--无检查证书--输出文档ttt.htm“$UPS\u URL”
任何其他解决方法都会非常有用。您使用了错误的页面和请求方法来获取数据。我访问了您链接到的页面,它只包含一个文本框,您可以在其中添加装运编号,然后将您重定向到包含结果的页面 因此,在此页面上简单地调用Wget将不会起任何作用。您需要知道要调用以获取详细信息的确切URI。我在浏览器上打开网络工具,看到了网络请求。单击提交后,它会发送一个
POST
请求,对它的响应包含您需要的所有数据。从那里提取,我构建了这个请求:
$ cat ups-request
{
"Locale": "en_US",
"TrackingNumber": [
"45234534263"
]
}
这是一个JSON字符串,包含所有要跟踪的包编号。你甚至可以添加更多的数字(该网站声称它可以同时处理多达25个数字)。文件准备好后,调用Wget:
$ wget --method=POST --body-file=ups-request --header="Content-Type: application/json" "https://www.ups.com/track/api/Track/GetStatus?loc=en_US"
在本例中,我们通过请求Wget发送POST请求(--method=POST
),发送我们在body中创建的JSON请求(--body file=ups request
),并告诉Wget请求的类型为JSON(--header=“Content type:application/JSON”
)。然后,服务器回复请求的完整详细信息:
{
"statusCode": "200",
"statusText": "Successful",
"isLoggedInUser": false,
"trackedDateTime": "02/14/2019 7:53 A.M. EST",
"isBcdnMultiView": false,
"trackDetails": [
{
"errorCode": "504",
"errorText": "Tracking number not found in database",
"requestedTrackingNumber": "45234534263",
"trackingNumber": "45234534263",
"isMobileDevice": false,
"packageStatus": null,
"packageStatusType": null,
"packageStatusCode": null,
"progressBarType": null,
"progressBarPercentage": null,
"simplifiedText": null,
"scheduledDeliveryDayCMSKey": null,
"scheduledDeliveryDate": null,
"noEstimatedDeliveryDateLabel": null,
"scheduledDeliveryTime": null,
"scheduledDeliveryTimeEODLabel": null,
"packageCommitedTime": null,
"endOfDayResCMSKey": null,
"deliveredDayCMSKey": null,
"deliveredDate": null,
"deliveredTime": null,
"receivedBy": null,
"leaveAt": null,
"leftAt": null,
"shipToAddress": null,
"shipFromAddress": null,
"consigneeAddress": null,
"signatureTrackingUrl": null,
"trackHistoryDescription": null,
"additionalInformation": null,
"specialInstructions": null,
"proofOfDeliveryUrl": null,
"upsAccessPoint": null,
"additionalPackagesCount": null,
"attentionNeeded": null,
"shipmentProgressActivities": null,
"trackingNumberType": null,
"preAuthorizedForReturnData": null,
"shipToAddressLblKey": null,
"trackSummaryView": null,
"senderShipperNumber": null,
"internalKey": null,
"userOptions": null,
"sendUpdatesOptions": null,
"myChoiceUpSellLink": null,
"bcdnNumber": null,
"promo": null,
"whatsNextText": null,
"packageStatusTimeLbl": null,
"packageStatusTime": null,
"myChoiceToken": null,
"showMycTerms": false,
"showConfirmWindow": false,
"confirmWindowLbl": null,
"confirmWindowLink": null,
"followMyDelivery": null,
"fileClaim": null,
"viewClaim": null,
"flightInformation": null,
"voyageInformation": null,
"viewDeliveryReceipt": null
}
]
}
我投票决定结束这个话题,因为它已经脱离主题了。与SuperUser.url更相关的内容可能会重定向到其他url。使用
curl-k-v-L
重定向站点并设置正确的URL