Can webbrowser module get source code?

M

Muddy Coder

Hi All,

I played the demo of webbrowser module, with the code below:

import webbrowser
url = 'https://login.yahoo.com'
webbrowser.open_new_tab(url)

when I ran the code, it popped out a webpage nicely. I want to go
further: to get the source code of the webpage being displayed. Is it
possible to do it? I tried webbrow.get() but didn't work. Somebody can
help? Thanks!


Muddy Coder
 
B

Benjamin Peterson

Muddy Coder said:
I want to go
further: to get the source code of the webpage being displayed. Is it
possible to do it? I tried webbrow.get() but didn't work. Somebody can
help? Thanks!

To do this, you actually need to fetch the page yourself:

import urllib2
page_source = urllib2.urlopen("http://someaddress.com").read()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top