can lxml/requests select dropdown options then parse resulting ajax?

前端 未结 1 468
一生所求
一生所求 2021-01-03 14:15

I have a site I\'m trying to test and although I can get a list of options in a dropdown I am not sure how select it? There is no submit button so if I select it then it wi

1条回答
  •  -上瘾入骨i
    2021-01-03 14:32

    With lxml+requests setup, you operate on a different level, a lower level. There are no dropdowns for requests, it is not a browser.

    The general approach to your problem is to:

    • open Browser Developer Tools in your browser of choice, Network tab
    • select an option in the dropdown
    • observe the request(s) sent to the server in the Network tab
    • simulate this/these requests in your Python code

    There is one more "trick" that you can use to ease the developer tools to requests transition:

    • right click on the request in the list of requests in Network tab
    • click "Copy as cURL"
    • go to http://curl.trillworks.com/ webpage and convert the cURL command to the Python+Requests code

    0 讨论(0)
提交回复
热议问题