开发者

(i'm close - i think) Python loop through list of subdomains with selenium

开发者 https://www.devze.com 2022-12-08 17:31 出处:网络
starting with a base URL, I\'m trying to have selenium loop through a short list of subdomains in csv format (ie: one column of 20 subdomains) and printing the html for each. I\'m having trouble figur

starting with a base URL, I'm trying to have selenium loop through a short list of subdomains in csv format (ie: one column of 20 subdomains) and printing the html for each. I'm having trouble figuring it out. Thanks!

from selenium import selenium
import unittest, time, re, csv, logging

subds = csv.reader(open('listofsubdomains.txt', 'rb'))
for subd in subds:
        try:
            class Untitled(unittest.TestCase):
                def setUp(self):
                    self.verificationErrors = []
                    self.selenium = selenium("localhost", 4444, "*firefox", "http://www.sourcedomain.com")
                    self.selenium.start()

                def test_untitled(self):
                    sel = self.selenium
                    sel.open(subd[0])
                    html = sel.get_html_source()
                    print html

                def tearDown(self):
                    self.selenium.stop()
                    self.assertEqual([], self.verificationErrors)

            if __name__ == "__main__":
                unittest.main()

        except Excep开发者_如何学编程tion, e:
            print>>sys.stderr, "Url % not processed: error (%s) % (url, e)"


You're defining the same function again and again in the body of the class. The class is completely created before unittest.main() starts, so only one test method will remain in the class.

0

精彩评论

暂无评论...
验证码 换一张
取 消