I have a twill script that I am trying to use to get the html code from a web page and output to a text file. The problem I have is that all the code does not show up in my text file. The actual parts I need are left out. When I go to the web page manually and do "View, Page Source" I can see all the information. Here is a sample of the script I am using (website, username and password have been changed.


import twill, string, os
import csv
import urllib2

from twill import get_browser
b = get_browser()
from twill.commands import *


b.go ("http://www.test.com/login")

username="user"
password="password"


formvalue ("form1", "name", "$username")
formvalue ("form1", "password", "$password")
b.submit

b.go ("http://www.test.com/testitem")

redirect_output ("c:\testhtml.txt")

html=b.get_html()

html

Does anyone know what the problem is?

You forgot to push the (CODE) button. I can not answer your question as the code does not run, but some things I have commented here.

import twill, string, os ## not used
import csv ## not used
import urllib2 ## not used

from twill import get_browser
b = get_browser()
from twill.commands import *


b.go ("http://www.test.com/login")

username="user"
password="password"


formvalue ("form1", "name", "$username")
formvalue ("form1", "password", "$password")
b.submit

b.go ("http://www.test.com/testitem")

redirect_output ("c:\testhtml.txt")


html=b.get_html()

html  ## does nothing

I proved the end as I have no login forms after easy_install twill:

from twill import get_browser
b = get_browser()
from twill.commands import *

redirect_output ("c:\\testhtml.txt") ## one \ was missing, contents: ==> at http://www.daniweb.com/
b.go ("http://www.daniweb.com/")
html=b.get_html()
print(html) ## print was missing
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.