Issue
I want to write a small code in python to check my parcels daily. While making a query in the web page (https://www.internationalparceltracking.com/#/search) URL doesn't change, so it is impossible to send the query by URL. I tried to use beautifulsoup and urllib but couldn't get the return.
Here, what I tried:
import requests
from bs4 import BeautifulSoup
url = 'https://www.internationalparceltracking.com/#/search'
html = urlopen(url).read()
soup = BeautifulSoup(html, "html.parser")
r = requests.post(url=url, data={'placeholder':'3SABC1234567890'})
print(r.text)
Lastly, I don't want to use selenium (like opening an extra browser) I want, the query is made in underground... I am waiting for your advice
Solution
I went to the url you posted. I filled out some dummy data in the form, opened up the Chrome Developer Console -> Network Tab, and was able to spot an outgoing GET request:
curl 'https://www.internationalparceltracking.com/api/shipment?barcode=OEIOEWJOE4WO4UOI4O43U34&checkIfValid=true&country=US&language=en&postalCode=94107' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Accept: application/json, text/plain, */*' -H 'Referer: https://www.internationalparceltracking.com/' -H 'Cookie: ROUTEID=route.2; TIN-Language=en; Ely_vID=vk51m7caca6fj45lhcauwgj67rg1cvsj' -H 'Connection: keep-alive' --compressed
Given that, I think the following code below will do (no need to scrape):
import requests
payload = {
'barcode': '3SABC1234567890',
'country': 'US',
'postalCode': 11111,
'language': 'en',
'checkIfValid': True
}
url = 'https://www.internationalparceltracking.com/api/shipment'
r = requests.get(url, params=payload)
print r.contents
Answered By - FelizNaveedad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.