user3344371
user3344371

Reputation: 1

How can i put a value in HTML and execute a python code with that value as a variable

I found this Python code:

#! C:\python27

import urllib2
from bs4 import BeautifulSoup
url='http://www.google.com/'

conn = urllib2.urlopen(url)
html = conn.read()  

soup = BeautifulSoup(html)
links = soup.find_all('a')

for tag in links:
    link = tag.get('href',None)
    if link != None:
        print link

And I need to make an HTML page that asks for the url value so when I type it, it changes the value on the python file and crawl the page I typed. I have a simple HTML code that asks the user for the URL he wants to crawl and has a input text so he can type what he wants, but how can I make the value that the user types to be the value of the url variable.

<form name="input" action="#" method="post">
Type in the page you want to crawl:<input type="text" name="url" value="http://www.google.com/"><br/>
<input type="submit" value="Submit">
</form>

How can I do that? New to Python, I have only worked with JavaScript before.

Upvotes: -1

Views: 148

Answers (1)

merlin2011
merlin2011

Reputation: 75565

Since the user has direct access to the Python script, there is no need to go through an HTML form.

You can ask for the user to input the url directly to the Python program.

Just write:

url = raw_input("Please enter a URL to crawl: ")

Upvotes: 1

Related Questions