Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python request (post/get)
#1
Question 
Is using requests post method the correct way to fill in a search box on a website?

I have been reading the docs and they all seem to suggest using the requests get method adding the search query to the url.

The problem I have is the website uses a search box which I need to put text in (I think). So I need to
  • go to page
  • Locate search box
  • Enter text
  • Submit
  • Scrape results

The site uses json as well and I am not sure if that would make a difference to how the code would need done.

Any help with what I should be looking at would be greatly appreciated.

(https://online.transport.wa.gov.au/webEx...20409949?0)

This is the page that the search box is on.

https://online.transport.wa.gov.au/webEx...ket/page?1

This is the results page after a search.

I can use selenium to carry out what I want to do but I want to do it with just python and requests as selenium is not compatible with my iPhone and Pythonista.

I could use mechanize, but I would still prefer to do it with just python.

https://online.transport.wa.gov.au/webEx...1684915326

This is from inspecting the header after I have pasted in the full Rego

https://online.transport.wa.gov.au/webEx...tration/?0

This is what the URL looks like before any information is passed into the search box.

I assume i need to do something with this part of the URL

-1.IBehaviorListener.2-layout-layout_body-registrationRequestForm-plate&random=0.49404731684915326)

I don't understand how I can replace the plate&random.

The request content type is

application/x-www-form-urlencoded;charset=UTF-8

requests.post('https://httpbin.org/post', data={'key':'value'})
Can anyone explain this for me? I think i need to fill the dictionary with the rego something like

requests.post('https://online.transport.wa.gov.au/webExternal/registration/post', data={'plate' : 'rego'}
Getting confused cant rreally locate an example of what i am trying to do


import requests

URL = "https://online.transport.wa.gov.au/webExternal/registration/?0"

rego = "1hdv243"

PARAMS = {'plate':rego}

response = requests.get(url = URL, params = PARAMS)

results = requests.get('https://online.transport.wa.gov.au/webExternal/registration/wicket/page?2')


print(response.headers)
print(results.json)
print(results.content)
print(results.text)
print(results.headers)
print(results.body)
Some code i have been trying.

Seems to pull some stuff back but not what i want…

And also says page has expired
Larz60+ write Jan-19-2023, 06:06 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use BBCode tags on future posts
Reply
#2
Please paste the code in code format. It's really hard to understand the code if you just paste it as text.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Post request not saving in DRF Dexty 0 927 Jun-03-2022, 12:35 PM
Last Post: Dexty
Brick how to work with 2 or more related tables in a Post request ikurorox 0 1,403 Dec-05-2021, 01:01 AM
Last Post: ikurorox
  POST request with form data issue web scraping hoff1022 1 2,691 Aug-14-2020, 10:25 AM
Last Post: kashcode
  The correct POST request abhie_lp 5 2,991 Jun-05-2020, 07:27 AM
Last Post: buran
  How to apply post request in python for establishment search for EPFO? rajeev1729 0 1,887 May-01-2020, 04:45 PM
Last Post: rajeev1729
  Handle parameters in POST request for python webserver? JBristow1729 1 7,768 Jul-16-2019, 10:59 PM
Last Post: scidam
  submit element from a list into a post request Godzilla 0 3,955 Mar-24-2018, 02:35 PM
Last Post: Godzilla
  I need request POST for Facebook in My Profile Kalet 4 4,319 Sep-27-2017, 05:53 PM
Last Post: Kalet

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020