Hello, I am very new to Python and have, what I think, is a rather simple question.

First, I am running Python 2.1 on Win XP. What I want to do is open a CF page after my process has run and pass the processID, that I will set, and the exit code value to it. The CF page will then insert the values to a SQL table. I have tried to just get Python to open a URL using the URLLIB but have been unsuccessful. Here is a sample what I have tried:

import urllib
url = ‘http://www.google.com
page = urllib.urlopen(url)
pagedata = page.read()

Any help would be greatly appreciated. Thanks.

Also, if there is a way for Python to post to a SQL table directly without using an intermediate CF page I would be interested in learning how. Thanks again.

Try this code, I think it's the one I posted on the "Starting Python" sticky here.

# if you are on the internet you can access the HTML code of a 
# given web site
# using the urlopen() method/function from the module urllib2

import urllib2

urlStr = 'http://www.python.org/'
try:
  fileHandle = urllib2.urlopen(urlStr)
  str1 = fileHandle.read()
  fileHandle.close()
  print '-'*50
  print 'HTML code of URL =', urlStr
  print '-'*50
except IOError:
  print 'Cannot open URL %s for reading' % urlStr
  str1 = 'error!'
  
print str1

First try to use it as is, then you can change the URL and give it another try. I know this one works and is tested with Python24 and a normal dialup connection.

I am trying to open the page "http://www.google.co.in/search?q=test+filetype%3Adoc" using this but this is not reading the page.

I have a requirement of fetching the first URL and saving it in another file. Could you please help me in this.

My requirement is :
1. Go to google.
2. Search anything.
3. Get the URL for the first link
4. Save the URL.

Please help me in doing this.

Thanks,
Rajesh

Also, if you are sitting behind a firewall, you might well get blocked unless you enable Python.

Jeff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.