You can get a web page's source code in Python using the requests
or urllib
library. Here are examples using both libraries:
main.py126 chars7 lines
main.py144 chars7 lines
Both examples send an HTTP GET request to the specified URL and retrieve the web page's source code as a string. The second example uses urllib
's urlopen
function to retrieve the web page's content. Note that you can also use additional libraries like BeautifulSoup
to parse the HTML source code.
gistlibby LogSnag