简体   繁体   中英

Lightweight Python Web Browser

Got a bit of weird request here, however it's one which I can't really figure out the answer to.

I'm writing a python application that displays web pages and locally stored images.

What I need is a way of displaying a web page using python that is really lightweight and quite fast. The reason for this is that it is running on a Raspberry Pi.

Of course I have many options, I can run it through web browser installed on the Raspbian distribution and run it as a separate process in python, I can download an Arch-Linux compatible browser and run it as a separate process in python and finally I can write my own native python file using Gtk or PyQt.

All of these approaches have their downsides as well as serious overheads. The web browser must also be full screen when I have a web page to display, and minimised when I'm displaying an image.

The main issue I have had with Gtk and PyQt is the way they have to be executed on the main thread - which is impossible as it doesn't align with my multithreaded architecture. The downside to using the web browsers that are pre-installed on raspbian, is that from python you lack control and it's slow. And finally, the issue with using an Arch-Linux browser is that it ends up being messy and hard to control.

What I would Ideally need is a web browser that loads a web page almost instantaneously, or a multithreaded web browser that can handle multiple instances. This way I can buffer one web page in the background whilst another browser is being displayed.

Do you guys have any advice to point me in the right direction? I would've thought that there would be a neat multithreaded python based solution by now, and I would think that's either because no one needs to do what I'm doing (less likely) - or I'm missing something big (more likely)!

Any advice would be appreciated.

James.

我会使用PyQT来显示页面,但是如果PyQT使用线程的方式不适合您的应用程序,则可以使用PyQT编写一个最低限度的Web浏览器(在这里我说的是大约10行代码),并将其派生从您的主要应用程序?

The solution that I came to was to use a couple of frame buffer browsers for linux called: netsurf-fb and links2 with -.

However after extensive testing - i decided it was not appropriate to use these due to the fact that they don't have javascript support.

Therefore the end solution was to use a script called cutycapt running in a virtual x window frame buffer called xvfb.

I called it from python using the pxpect library like so:

process=pexpect.spawn(xvfb_run_bin+' --server-args "-screen 0, '+self.width_height+'x24" cutycapt --url='+uri+' --out='+temp_path)
        process.wait()

This in my implementation goes off, renders the page and saves the screen shot. An image viewer then fetches the image from my cache and displays it.

If anyone has any further questions - feel free to comment on this question...

IMPORT cutecapt information. If you want to render a whole page using javascript it will take longer... specify the --delay 1000 where it will delay the loading by 1 second in this instance. For me it took around 7000 to get it just right...

i have written winks-up in vala. It's small and fast and compile well on raspbian. All the code was optimize to reduce memory occupation. isn't perfect but was better like nothing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM