-1

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.

Cory Kramer
119k19 gold badges177 silver badges233 bronze badges
asked Apr 13, 2014 at 17:04
2
  • Is the Python code sitting on a server somewhere that the user does not have access to, or can the user also run the Python code directly? Commented Apr 13, 2014 at 17:10
  • he can run it directly Commented Apr 13, 2014 at 17:17

1 Answer 1

1

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: ")
answered Apr 13, 2014 at 17:22
Sign up to request clarification or add additional context in comments.

3 Comments

When ever I try to run the program on CMD it closes without making the crawl. It does crawls the page but the program closes without giving me the change to see the results.
@user3344371, That is a little bit unusual. Usually that only happens if you execute the command by double-clicking. Can you confirm that you are opening cmd.exe, and then typing python myscript.py on the command line?
I was actually running it with Python rather then the CMD, but thank you I found a way to fixed. :D

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.