Reputation:
Im using get request to get data from a site.
captured reqeuest details :
Query String Parameters
s: vrnf8
following is my code . But i get 404 not found status code.
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
print(resp.text)
print(resp.status_code)
please help me with this !
request capture file : https://filebin.net/ilx668e5yrdmbu7p
response must be this :
[[{"lastreport_class": "position-age-live", "course": 213, "callsign": "VRNF8", "lastreport_verbose": "2020-07-17 12:28 UTC", "speed": 15.6, "destination": "SGSIN PEBGA", "vessel_url": "/vessels/seaspan-amazon_9630391_8896228/", "imo": "9630391", "location": "South Kuroshio, JP", "latitude": 28.732660, "vesselid": "8896228", "mmsi": "477390400", "lastreport_timestamp": 1594985298, "lastreport_short": "21 min", "name_clean": "SEASPAN AMAZON", "vessel_type": "Container ship", "master_image_id": 2278121, "flag_id": "HK", "icon": "cargo", "is_moving": true, "name": "SEASPAN AMAZON", "longitude": 28.732660, "length": "337", "flag_name": "Hong Kong SAR of China"}], 1, [], 0]
Upvotes: 1
Views: 1024
Reputation: 12672
Try this code below:
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
headers = {
'X-Requested-With': 'XMLHttpRequest'
}
response = requests.get(url, headers=headers)
print(response.json())
Result:
[[{'lastreport_class': 'position-age-live', 'course': 212, 'callsign': 'VRNF8', 'lastreport_verbose': '2020-07-17 13:22 UTC', 'speed': 15.9, 'destination': 'SGSIN PEBGA', 'vessel_url': '/vessels/seaspan-amazon_9630391_8896228/', 'imo': '9630391', 'location': 'South Kuroshio, JP', 'latitude': 28.540143, 'vesselid': '8896228', 'mmsi': '477390400', 'lastreport_timestamp': 1594988550, 'lastreport_short': '1 min', 'name_clean': 'SEASPAN AMAZON', 'vessel_type': 'Container ship', 'master_image_id': 2278121, 'flag_id': 'HK', 'icon': 'cargo', 'is_moving': True, 'name': 'SEASPAN AMAZON', 'longitude': 28.540143, 'length': '337', 'flag_name': 'Hong Kong SAR of China'}], 1, [], 0]
Upvotes: 1
Reputation: 109
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
print(resp.text)
print(resp.status_code)
NOTE: The url you have typed doesn't exist
Correct Code
import requests
url = "https://www.fleetmon.com/search/"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
print(resp.text)
print(resp.status_code)
But Now also you will get an error
let's understand what's happening in your code
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
'''
resp is equivalent to request.get("https://www.fleetmon.com/search/?s=vrnf8/?s=vrnf8")
when we make get request to url, it appends /?query=value to it's requested url
and this url doesn't exist so you will get 404
'''
print(resp.text)
print(resp.status_code)
code that I sent
```python
import requests
url = "https://www.fleetmon.com/search"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
'''
resp is equivalent to request.get("https://www.fleetmon.com/search/?s=vrnf8")
when we make get request to url, it again appends /?query=value to it's requested url
and even this url also doesn't exist so you will again get 404
'''
print(resp.text)
print(resp.status_code)
NOTE: You can check weather a url exist or not by typing it in google search bar
Upvotes: 0