Пример #1
0
def main():
   webclient = WebClient(BrowserVersion.FIREFOX_3_6) # creating a new webclient object.
   url = "http://www.gartner.com/it/products/mq/mq_ms.jsp"
   page = webclient.getPage(url) # getting the url
   articles = page.getByXPath("//table[@id='mqtable']//tr/td/a") # getting all the hyperlinks
   for article in articles:
        print "Clicking on:", article
        subpage = article.click() # click on the article link13
        title = subpage.getByXPath("//div[@class='title']") # get title

        summary = subpage.getByXPath("//div[@class='summary']") # get summary
        if len(title) > 0 and len(summary) > 0:
             print "Title:", title[0].asText()

             print "Summary:", summary[0].asText()
Пример #2
0
class SimpleTest(unittest.TestCase):
    def setUp(self):
        import com.gargoylesoftware.htmlunit.WebClient as WebClient
        self.webclient = WebClient()
        self.client = Client()

    def test_create_ledger(self):
        response = self.client.post('/ledger/create/', {'currency': '1', 'name': 'test{}'.format(time.time())})
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, 'http://testserver/ledger/1')

    def test_invalid_ledger(self):
        response = self.client.post('/ledger/create/', {'currency': '', 'name': 'test{}'.format(time.time())})
        with tempfile.NamedTemporaryFile(delete=False) as f:
            for match in re.finditer(r'"//([^"]+)"', response.content):
                url = match.group(1)
                if not os.path.exists(url): subprocess.check_output(["wget", "--no-clobber", "--mirror", url], stderr=subprocess.STDOUT)
            f.write(response.content.replace("\"//", "\"file://{}/".format(os.getcwd())).replace("\"/static/","\"http://*****:*****@class, 'alert')]")
        assert alert is not None, "post was invalid, there should be an alert"
        print(alert.asText())
Пример #3
0
class SimpleTest(unittest.TestCase):
    def setUp(self):
        import com.gargoylesoftware.htmlunit.WebClient as WebClient
        self.webclient = WebClient()
        self.client = Client()

    def test_create_ledger(self):
        response = self.client.post('/ledger/create/', {
            'currency': '1',
            'name': 'test{}'.format(time.time())
        })
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, 'http://testserver/ledger/1')

    def test_invalid_ledger(self):
        response = self.client.post('/ledger/create/', {
            'currency': '',
            'name': 'test{}'.format(time.time())
        })
        with tempfile.NamedTemporaryFile(delete=False) as f:
            for match in re.finditer(r'"//([^"]+)"', response.content):
                url = match.group(1)
                if not os.path.exists(url):
                    subprocess.check_output(
                        ["wget", "--no-clobber", "--mirror", url],
                        stderr=subprocess.STDOUT)
            f.write(
                response.content.replace("\"//", "\"file://{}/".format(
                    os.getcwd())).replace(
                        "\"/static/",
                        "\"http://*****:*****@class, 'alert')]")
        assert alert is not None, "post was invalid, there should be an alert"
        print(alert.asText())
Пример #4
0
 def setUp(self):
     import com.gargoylesoftware.htmlunit.WebClient as WebClient
     self.webclient = WebClient()
     self.client = Client()
        print(jarpath+jar+'\n')
        container = jarpath+jar
        sys.path.append(container)

# loadjars()

import com.gargoylesoftware.htmlunit.WebClient as WebClient

import com.gargoylesoftware.htmlunit.BrowserVersion as BrowserVersion

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException
import com.gargoylesoftware.htmlunit.html.HtmlPage
import com.gargoylesoftware.htmlunit.ScriptException


try:webclient = WebClient(BrowserVersion.CHROME) # creating a new webclient object.
except:
    webclient = WebClient() # creating a new webclient object.
try:
        webclient.getOptions().setThrowExceptionOnScriptError(False)
        webclient.getOptions().setRedirectEnabled(True);
        webclient.getOptions().setThrowExceptionOnScriptError(False);
        webclient.getOptions().setCssEnabled(False);
        webclient.getOptions().setUseInsecureSSL(True);
        webclient.getOptions().setThrowExceptionOnFailingStatusCode(False);
        webclient.getCookieManager().setCookiesEnabled(True);
except:
        print "error in webcline options \n"
def main():
   # try:webclient = WebClient(BrowserVersion.FIREFOX_3_6) # creating a new webclient object.
   # except:webclient = WebClient() # creating a new webclient object.
Пример #6
0
 def setUp(self):
     import com.gargoylesoftware.htmlunit.WebClient as WebClient
     self.webclient = WebClient()
     self.client = Client()
Пример #7
0
        print(jarpath+jar+'\n')
        container = jarpath+jar
        sys.path.append(container)

# loadjars()

import com.gargoylesoftware.htmlunit.WebClient as WebClient

import com.gargoylesoftware.htmlunit.BrowserVersion as BrowserVersion

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException
import com.gargoylesoftware.htmlunit.html.HtmlPage
import com.gargoylesoftware.htmlunit.ScriptException


try:webclient = WebClient(BrowserVersion.FIREFOX_3_6) # creating a new webclient object.
except:
    webclient = WebClient() # creating a new webclient object.
    try:
        webclient.getOptions().setThrowExceptionOnScriptError(False)
        webclient.getOptions().setRedirectEnabled(True);
        webclient.getOptions().setThrowExceptionOnScriptError(False);
        webclient.getOptions().setCssEnabled(False);
        webclient.getOptions().setUseInsecureSSL(True);
        webclient.getOptions().setThrowExceptionOnFailingStatusCode(False);
        webclient.getCookieManager().setCookiesEnabled(True);
    except:
        print "error in webcline options \n"
def main():
   # try:webclient = WebClient(BrowserVersion.FIREFOX_3_6) # creating a new webclient object.
   # except:webclient = WebClient() # creating a new webclient object.
Пример #8
0
def gotopage():
	webclient = WebClient() # creating a new webclient object.
def executeSSOTest():
    reqInstant = dateFormat.format(GregorianCalendar(utctz).getTime())
    reqId = UUID.randomUUID().toString()
    authnRequest = props.get('shib.sp.authnreq') % (idpSSOEndpoint, reqId,
                                                    reqInstant, spId)

    webClient = WebClient()
    webClient.setUseInsecureSSL(True)
    listreq = ArrayList()
    listreq.add(
        NameValuePair(
            "SAMLRequest",
            String(Base64.encodeBase64(String(authnRequest).getBytes()),
                   'US-ASCII')))
    wrs = WebRequestSettings(URL(idpSSOEndpoint), HttpMethod.POST)
    wrs.setRequestParameters(listreq)

    if props.get('shib.idp.auth') == 'FORM':
        webClient.setRedirectEnabled(True)

        if debug: log("sending SSO request to: " + idpSSOEndpoint, stdout)
        wr = webClient.loadWebResponse(wrs)
        if debug: log("Response content: \n" + wr.getContentAsString(), stdout)

        if wr.getStatusCode() != 200:
            raise Exception('Invalid HTTP response code: ' +
                            str(wr.getStatusCode()))
        wrs.setHttpMethod(HttpMethod.POST)
        listauth = ArrayList()
        listauth.add(NameValuePair("j_username", props.get('shib.user.name')))
        listauth.add(NameValuePair("j_password", props.get('shib.user.pass')))
        wrs.setRequestParameters(listauth)
        wrs.setUrl(wr.getRequestUrl())
    else:
        # BASIC auth
        webClient.setRedirectEnabled(False)

        if debug: log("sending SSO request to: " + idpSSOEndpoint, stdout)
        wr = webClient.loadWebResponse(wrs)
        if debug: log("Response content: \n" + wr.getContentAsString(), stdout)

        if wr.getStatusCode() != 302:
            raise Exception('Invalid HTTP response code: ' +
                            str(wr.getStatusCode()))
        wrs.setHttpMethod(HttpMethod.GET)
        creds = DefaultCredentialsProvider()
        creds.addCredentials(props.get('shib.user.name'),
                             props.get('shib.user.pass'), idpHost, idpPort,
                             props.get('shib.user.realm'))
        wrs.setCredentialsProvider(creds)

        if debug:
            log(
                "sending BASIC auth to: " +
                wr.getResponseHeaderValue('Location'), stdout)
        wrs.setUrl(URL(wr.getResponseHeaderValue('Location')))

    if debug:
        log("sending login request to: " + str(wr.getRequestUrl()), stdout)
    wr = webClient.loadWebResponse(wrs)

    if debug:
        log("Request URL = " + wr.getRequestUrl().toString(), stdout)
        log(wr.getContentAsString(), stdout)

    if wr.getStatusCode() not in [200, 301, 302]:
        if debug: log("error response: " + response.getText(), stdout)
        raise Exception('Invalid HTTP response code: ' +
                        str(wr.getStatusCode()))
    return wr.getContentAsString()