I want to get the result of the web page http://www3.hkexnews.hk/listedco/listconews/advancedsearch/search_active_main.aspx
with the input of stock code being 5.
The problem is that I don't know the website after pressing search as it runs a javascript.
Furthermore, how to find the parameters needed to pass to requests.post
, e.g. data? Is header needed?
You have multiple options:
1) You can use Selenium. First install Selenium.
Then get a driver https://sites.google.com/a/chromium.org/chromedriver/downloads (Depending upon your OS you may need to specify the location of your driver)
2) Or use PyQt with QWebEngineView.
Install PyQt on Ubuntu:
or on other OS (64 bit versions of Python)
Basically you load the first page with the form on. Fill in the form by running JavaScript then submit it. The loadFinished() signal is called twice, the second time because you submitted the form so you can use an if statement to differentiate between the calls.
Outputs:
Alternatively you can use Scrapy splash https://github.com/scrapy-plugins/scrapy-splash
Or Requests-HTML https://html.python-requests.org/ .
But I am not sure how you would fill the form in using these two last approaches.
Updated how to read the next pages: