Adding query parameters to a URL
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm trying to automate data download from a website. I need to pass dynamic parameters to the site that changes daily. The html is structured in a table rather than forms. How do I pass my parameters and get a result from the url?
This is what I tried and it needs to be in python 2.7
import urllib
url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
params = urllib.urlencode({'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"})
r = urllib.urlopen(url, params)
return = r.read()
python python-2.7 url web-scraping urllib
add a comment |
I'm trying to automate data download from a website. I need to pass dynamic parameters to the site that changes daily. The html is structured in a table rather than forms. How do I pass my parameters and get a result from the url?
This is what I tried and it needs to be in python 2.7
import urllib
url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
params = urllib.urlencode({'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"})
r = urllib.urlopen(url, params)
return = r.read()
python python-2.7 url web-scraping urllib
add a comment |
I'm trying to automate data download from a website. I need to pass dynamic parameters to the site that changes daily. The html is structured in a table rather than forms. How do I pass my parameters and get a result from the url?
This is what I tried and it needs to be in python 2.7
import urllib
url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
params = urllib.urlencode({'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"})
r = urllib.urlopen(url, params)
return = r.read()
python python-2.7 url web-scraping urllib
I'm trying to automate data download from a website. I need to pass dynamic parameters to the site that changes daily. The html is structured in a table rather than forms. How do I pass my parameters and get a result from the url?
This is what I tried and it needs to be in python 2.7
import urllib
url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
params = urllib.urlencode({'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"})
r = urllib.urlopen(url, params)
return = r.read()
python python-2.7 url web-scraping urllib
python python-2.7 url web-scraping urllib
edited Jan 5 at 10:13
snakecharmerb
12.1k42552
12.1k42552
asked Jan 4 at 0:16
Zelalem Zelalem
61
61
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You need to append the query parameters to the base url, so that urllib.urlopen
creates a GET request.
>>> url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
>>> params = {'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"}
>>> quoted_params = urllib.urlencode(params)
>>> quoted_params
'bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> full_url = url + quoted_params
>>> full_url
'https://disc.gsfc.nasa.gov/SSW/#keywords=bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> resp = urllib.urlopen(full_url)
>>> html = resp.read()
Thank you for this. I was able to make this work but have a different challenge now implementing it in IronPython 2.7.7. Please see my answer below and let me know if you can help. T
– Zelalem
Jan 24 at 3:04
add a comment |
I was able to Make this work in Python 2.7 as shown below but in I need to implement this in IronPython 2.7.7 because of a software dependency. I am getting an error saying "unknown url type: https" I understand versions of IronPython before 2.7.9 have issues with https. Is there a way to bypass the security check?
>>> import urllib
>>> url_keys = urllib.urlencode( {'action': "SUBSET", 'no_attr_prefix': 1, 'content_key_is_value': 1, 'force_array': 1,
... 'pretty': 0, 'start': "2019-01-02T00:00:00Z", 'end': "2019-01-04T23:59:59Z", 'south': 0.28,
... 'west': 32.77, 'north': 13.64, 'east': 44.72, 'variables': "precipitationCal", 'format': "netCDF",
... 'dataset_id': "GPM Level 3 IMERG Early Half Hourly 0.1 x 0.1 degree Precipitation V05", 'agent_id': "OPeNDAP"})
>>> url = "https://disc.gsfc.nasa.gov/daac-bin/SSW/SSW"
>>> r = urllib.urlopen(url, url_keys)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54031584%2fadding-query-parameters-to-a-url%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to append the query parameters to the base url, so that urllib.urlopen
creates a GET request.
>>> url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
>>> params = {'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"}
>>> quoted_params = urllib.urlencode(params)
>>> quoted_params
'bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> full_url = url + quoted_params
>>> full_url
'https://disc.gsfc.nasa.gov/SSW/#keywords=bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> resp = urllib.urlopen(full_url)
>>> html = resp.read()
Thank you for this. I was able to make this work but have a different challenge now implementing it in IronPython 2.7.7. Please see my answer below and let me know if you can help. T
– Zelalem
Jan 24 at 3:04
add a comment |
You need to append the query parameters to the base url, so that urllib.urlopen
creates a GET request.
>>> url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
>>> params = {'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"}
>>> quoted_params = urllib.urlencode(params)
>>> quoted_params
'bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> full_url = url + quoted_params
>>> full_url
'https://disc.gsfc.nasa.gov/SSW/#keywords=bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> resp = urllib.urlopen(full_url)
>>> html = resp.read()
Thank you for this. I was able to make this work but have a different challenge now implementing it in IronPython 2.7.7. Please see my answer below and let me know if you can help. T
– Zelalem
Jan 24 at 3:04
add a comment |
You need to append the query parameters to the base url, so that urllib.urlopen
creates a GET request.
>>> url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
>>> params = {'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"}
>>> quoted_params = urllib.urlencode(params)
>>> quoted_params
'bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> full_url = url + quoted_params
>>> full_url
'https://disc.gsfc.nasa.gov/SSW/#keywords=bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> resp = urllib.urlopen(full_url)
>>> html = resp.read()
You need to append the query parameters to the base url, so that urllib.urlopen
creates a GET request.
>>> url = "https://disc.gsfc.nasa.gov/SSW/#keywords="
>>> params = {'keyword':"(GPM_3IMERGHHE)", 't1':"2019-01-02", 't2':"2019-01-03", 'bboxBbox':"3.52,32.34,16.88,42.89"}
>>> quoted_params = urllib.urlencode(params)
>>> quoted_params
'bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> full_url = url + quoted_params
>>> full_url
'https://disc.gsfc.nasa.gov/SSW/#keywords=bboxBbox=3.52%2C32.34%2C16.88%2C42.89&t2=2019-01-03&keyword=%28GPM_3IMERGHHE%29&t1=2019-01-02'
>>> resp = urllib.urlopen(full_url)
>>> html = resp.read()
answered Jan 5 at 10:12
snakecharmerbsnakecharmerb
12.1k42552
12.1k42552
Thank you for this. I was able to make this work but have a different challenge now implementing it in IronPython 2.7.7. Please see my answer below and let me know if you can help. T
– Zelalem
Jan 24 at 3:04
add a comment |
Thank you for this. I was able to make this work but have a different challenge now implementing it in IronPython 2.7.7. Please see my answer below and let me know if you can help. T
– Zelalem
Jan 24 at 3:04
Thank you for this. I was able to make this work but have a different challenge now implementing it in IronPython 2.7.7. Please see my answer below and let me know if you can help. T
– Zelalem
Jan 24 at 3:04
Thank you for this. I was able to make this work but have a different challenge now implementing it in IronPython 2.7.7. Please see my answer below and let me know if you can help. T
– Zelalem
Jan 24 at 3:04
add a comment |
I was able to Make this work in Python 2.7 as shown below but in I need to implement this in IronPython 2.7.7 because of a software dependency. I am getting an error saying "unknown url type: https" I understand versions of IronPython before 2.7.9 have issues with https. Is there a way to bypass the security check?
>>> import urllib
>>> url_keys = urllib.urlencode( {'action': "SUBSET", 'no_attr_prefix': 1, 'content_key_is_value': 1, 'force_array': 1,
... 'pretty': 0, 'start': "2019-01-02T00:00:00Z", 'end': "2019-01-04T23:59:59Z", 'south': 0.28,
... 'west': 32.77, 'north': 13.64, 'east': 44.72, 'variables': "precipitationCal", 'format': "netCDF",
... 'dataset_id': "GPM Level 3 IMERG Early Half Hourly 0.1 x 0.1 degree Precipitation V05", 'agent_id': "OPeNDAP"})
>>> url = "https://disc.gsfc.nasa.gov/daac-bin/SSW/SSW"
>>> r = urllib.urlopen(url, url_keys)
add a comment |
I was able to Make this work in Python 2.7 as shown below but in I need to implement this in IronPython 2.7.7 because of a software dependency. I am getting an error saying "unknown url type: https" I understand versions of IronPython before 2.7.9 have issues with https. Is there a way to bypass the security check?
>>> import urllib
>>> url_keys = urllib.urlencode( {'action': "SUBSET", 'no_attr_prefix': 1, 'content_key_is_value': 1, 'force_array': 1,
... 'pretty': 0, 'start': "2019-01-02T00:00:00Z", 'end': "2019-01-04T23:59:59Z", 'south': 0.28,
... 'west': 32.77, 'north': 13.64, 'east': 44.72, 'variables': "precipitationCal", 'format': "netCDF",
... 'dataset_id': "GPM Level 3 IMERG Early Half Hourly 0.1 x 0.1 degree Precipitation V05", 'agent_id': "OPeNDAP"})
>>> url = "https://disc.gsfc.nasa.gov/daac-bin/SSW/SSW"
>>> r = urllib.urlopen(url, url_keys)
add a comment |
I was able to Make this work in Python 2.7 as shown below but in I need to implement this in IronPython 2.7.7 because of a software dependency. I am getting an error saying "unknown url type: https" I understand versions of IronPython before 2.7.9 have issues with https. Is there a way to bypass the security check?
>>> import urllib
>>> url_keys = urllib.urlencode( {'action': "SUBSET", 'no_attr_prefix': 1, 'content_key_is_value': 1, 'force_array': 1,
... 'pretty': 0, 'start': "2019-01-02T00:00:00Z", 'end': "2019-01-04T23:59:59Z", 'south': 0.28,
... 'west': 32.77, 'north': 13.64, 'east': 44.72, 'variables': "precipitationCal", 'format': "netCDF",
... 'dataset_id': "GPM Level 3 IMERG Early Half Hourly 0.1 x 0.1 degree Precipitation V05", 'agent_id': "OPeNDAP"})
>>> url = "https://disc.gsfc.nasa.gov/daac-bin/SSW/SSW"
>>> r = urllib.urlopen(url, url_keys)
I was able to Make this work in Python 2.7 as shown below but in I need to implement this in IronPython 2.7.7 because of a software dependency. I am getting an error saying "unknown url type: https" I understand versions of IronPython before 2.7.9 have issues with https. Is there a way to bypass the security check?
>>> import urllib
>>> url_keys = urllib.urlencode( {'action': "SUBSET", 'no_attr_prefix': 1, 'content_key_is_value': 1, 'force_array': 1,
... 'pretty': 0, 'start': "2019-01-02T00:00:00Z", 'end': "2019-01-04T23:59:59Z", 'south': 0.28,
... 'west': 32.77, 'north': 13.64, 'east': 44.72, 'variables': "precipitationCal", 'format': "netCDF",
... 'dataset_id': "GPM Level 3 IMERG Early Half Hourly 0.1 x 0.1 degree Precipitation V05", 'agent_id': "OPeNDAP"})
>>> url = "https://disc.gsfc.nasa.gov/daac-bin/SSW/SSW"
>>> r = urllib.urlopen(url, url_keys)
edited Jan 24 at 3:01
Paul Rooney
12.8k72845
12.8k72845
answered Jan 24 at 2:59
Zelalem Zelalem
61
61
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54031584%2fadding-query-parameters-to-a-url%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown