How to Scrollswipe Instagram Videos Programmatically From Pyqt6
Greg built a quick demo application https://github.com/gregbci/PyQtWeb.
- This works to open Instagram and log in. Posts can be viewed.
- Reels cannot be viewed right now- there is a Javascript video source error. When you try to view them, it shows a blurry thumbnail that looks like it is about to load, but it stops and says “Sorry, we’re having trouble playing this video.”

-
Instagram has an embed feature for their media (you can either click an “Embed” button on each individual reel on the website, or use the oEmbed code (https://developers.facebook.com/docs/instagram/oembed/). Maybe this can be used to solve the problem.
-
Even though the reels do not play, you can scroll through them using the space bar and the up/down arrow keys.
-
When trying to do an artificial key press event to scroll the instagram reels page, it does not work. The artificial scroll works on the main/explore/account pages. -
Keyboard events can be simulated by sending a QKeyEvent can be sent to the widget you want. Calling processEvents() causes the widget to consume the event. Use the WebView’s focusProxy() to ensure the event goes to the right HtmlElement within the page, though that probably doesn’t matter for down arrow.
event = QKeyEvent(QEvent.Type.KeyPress, Qt.Key.Key_Down, Qt.KeyboardModifier.NoModifier)
QCoreApplication.sendEvent(self.webEngineView.focusProxy(), event)
QCoreApplication.processEvents()
This is Qt code for a video player that accesses videos locally downloaded: https://doc.qt.io/qtforpython-6/examples/example_multimedia_player.html
- This works with a few edits, but if we want to use reels specifically there is a problem. Reels cannot be downloaded directly from Instagram. There are sketchy websites (https://sssinstagram.com/reels-downloader) that allow you to download them.
In essence: reels don’t play and I haven’t figured out how to scroll through them with an artificial keypress event.