I am trying to extract a URL from a text file. I am using PowerShell to do this. The last part of the URL will be different each time. A snippet of the file is as follows:
<table class="button" style="border-collapse: collapse; border-spacing: 0; overflow:
hidden; padding: 0; text-align: left; vertical-align: top; width: 100%;"><tbody>
<tr style="padding: 0; text-align: left; vertical-align: top;"><td style="-moz-hyphens: none;
-webkit-hyphens: none; -webkit-text-size-adjust: none; background: #049FD9;
border: none; border-collapse: collapse !important; border-radius: 2px; color: #fff; display: block; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 14px; font-weight: lighter; hyphens: none; line-height:19px; margin: 0; padding: 8px 16px; text-align: center; vertical-align: top; width: auto
!important; word-break: keep-all;">
<a href="https://www.website.com:443/idb/setPassword?t=BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D"
style="-webkit-text-size-adjust: none; font-weight: 100; color: #fff; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 20px; font-weight: lighter; line-height: 32px; text-decoration: none;">Get Started</a> </td></tr></tbody></table></td>
I want to extract the URL that starts with:
https://www.website.com:443/idb/setPassword
The string after the t= will be different each time. How can I extract the entire URL into a variable that I can then parse to get the info I need, which is the string of characters after the ?t=?
Try the following:
$content = Get-Content -Path 'C:\test.txt'
[regex]$regex = '(?<=href="https:\/\/www\.website\.com:443\/idb\/setPassword\?t=)(.*)(?=" )'
$regex.Matches($content).Value
In $content replace the path with your text file that contains the URL and update the $regex with the correct URL to the site.
This method use Regex to match before (?<= ) the websites URL and after (?= ), and then selects the text in the middle.
Here is a solution that uses a combination of Select-String with a regular expression to get the URL and the [system.uri] class to interrogate it.
$Text = get-content 'html-sample.txt'
$URLString = ((Select-String '(http[s]?)(:\/\/)([^\s,]+)(?=")' -Input $Text).Matches.Value)
#At this point $URL is a string with just the URL and querystring as requested
$URLString
#Heres how you might interrogate it
[system.uri]$URL = $URLString
$Token = ($URL.Query -split '=')[1]
$URL.host
$Token
Explanation:
Uses the regular expression (http[s]?)(:\/\/)([^\s,]+)(?=") with Select-String to extract the URL. Note this will only get the first match by default, use the -AllMatches switch of Select-String if you need to match multiple URLs and then you'll need to deal with each result via a ForEach loop.
Uses [system.uri] to cast the URL as a URI object.
Access the host property of the object to return the base URL.
Accesses the query property of the object to return the query string and replaces the '?t=' part of the string using a regex that only does the replace where it appears in the beginning of the string (^ token) and using backslashes to escape the other regex special characters.
here's another way by casting [xml] to read the file as an xmldocument....
$thisxml = [xml](gc .\hypertext.html)
then drill down to the node you want using xpath
$thisxpath = ($thisxml).SelectNodes("//table//tr//td//a").href
then cast [system.uri] to parse and select the uri pieces you want.
$thisuri = [System.Uri]$thisxpath | %{($_.Scheme + "://" + $_.host + $_.LocalPath)}
Related
First time here, so sorry for any lack of understanding in the code of conduct of this place.
I've already read the post with a similar described problem, but it didn't help :-/
Sorry, I'm a n00b, be gentle!
Just started structuring my sass into different files, and at the same time started using sass instead of scss.
My problem, which is probably really simple and stupid, is:
Compilation Error
Error: Invalid CSS after "...align: top; } }": expected 1 selector or at-rule, was "{"
on line 43 of Users/Test/Documents/walters.dk 6.0/styles/1-base/_typography.sass
from line 2 of Users/Test/Documents/walters.dk 6.0/styles/1-base/_base-dir.sass
from line 2 of sass/Users/Test/Documents/walters.dk 6.0/styles/app.sass
>> vertical-align: top; } } {
The file the error is originating from looks like this:
(Line 43 is the bottom one, "vertical-align: top")
// Text
h1
font-family: 'Raleway', sans-serif
font-weight: 300
display: inline-block
color: $redish
margin: 0 auto
text-align: center
font-size: 25px
line-height: 1
h2
font-family: 'waltershand', Arial, sans-serif
text-align: center
font-size: 10rem
margin-top: 3%
h3
font-family: 'waltershand', Arial, sans-serif
text-align: center
h4
font-family: 'Raleway', sans-serif
font-size: 0.85rem
font-weight: 600
display: inline-block
h5
font-size: 3rem
font-family: 'waltershand', Arial, sans-serif
margin: 4vh 5vw auto 5vw
z-index: 2
+mq(875px)
font-size: 4.4vw
display: inline-block
vertical-align: top
First time using mixins, so in case it helps, i have added the code below :
=mq($size)
#media only screen and (min-width: $size)
#content
The files compile into app.sass like this:
#import 'variables'
#import '1-base/base-dir'
I'm guessing the problem isn't in the actual line 43, but rather in the way my mixin is written, or the way its importet.
Here's hoping some brainy code master can help!
By removing this
+mq(875px)
font-size: 4.4vw
display: inline-block
vertical-align: top
Your code is good to go. I'm not sure about the mq what does it do ?
You can cleary see the error and try it out here
Error: no mixin named mq
Backtrace:
stdin:38
on line 38 of stdin
#include mq(875px) { -------------^
I am trying to extract a string of data from text file that I downloaded using EWS. I am using powershell to do this. A snippet of the file is as follows.
<table class="button" style="border-collapse: collapse; border-spacing: 0; overflow:
hidden; padding: 0; text-align: left; vertical-align: top; width: 100%;"><tbody>
<tr style="padding: 0; text-align: left; vertical-align: top;"><td style="-moz-hyphens: none;
-webkit-hyphens: none; -webkit-text-size-adjust: none; background: #049FD9;
border: none; border-collapse: collapse !important; border-radius: 2px; color: #fff; display: block; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 14px; font-weight: lighter; hyphens: none; line-height:19px; margin: 0; padding: 8px 16px; text-align: center; vertical-align: top; width: auto
!important; word-break: keep-all;">
<a href="https://www.website.com:443/idb/setPassword?t=BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D"
style="-webkit-text-size-adjust: none; font-weight: 100; color: #fff; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 20px; font-weight: lighter; line-height: 32px; text-decoration: none;">Get Started</a> </td></tr></tbody></table></td>
I want to extract this part BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D
I've tried -matches and using regex lookbehinds and forwards but nothing seems to be able to grab that part only.
Thought something like this might work
$a = Get-Content $path
$a -match '(?<=setPassword\?t\=)(.+)(?=" style)'
$matches
But it comes up blank
Best not to use string manipulation for this; use existing libraries and classes.
So first of all, treat your URI as a [uri]:
$uri = [System.Uri]'https://www.website.com/idb/setPassword?t=BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D'
Now you can get the query string like this:
$query = $uri.Query
That will start with ?t=, so let's parse it:
$queryData = [System.Web.HttpUtility]::ParseQueryString($query)
The resulting object has a set of keys, one for each value. Since the key you want is called t, you can get the value like this:
$queryData['t']
So I figured out the text document I was outputting to was word wrapping part of the long URL. I ended up outputting with the -Width command so it wouldn't do that.
$email | Out-File $path -Width 9999999
Then I ended up using matches to grab the string I needed using.
$a = Get-Content $path | Where-Object {$_ -match '(?<=https:\/\/www\.website\.com:443\/idb\/setPassword\?t=)(.+)(?=" style)'}
$matches[1]
Hope that helps someone.
Let's say I want to create a custom button element that extends the default html button tag.
My component would look more or less like this:
#Component({
selector: 'my-button',
styles: []
template: `<button><ng-content></ng-content></button>`
})
export class MyButton{}
The issue is that instead of a regular HTML button, I get the ionic2 button. How can I bypass the ionic 2 button component and create my own?
Have you tried with an anchor element?
<a class="my-button"><ng-content></ng-content></a>
and some default button styles like these (or the styles you want to apply to it):
a.my-button {
align-items: flex-start;
text-align: center;
cursor: default;
color: buttontext;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
background-color: buttonface;
box-sizing: border-box;
padding: 2px 6px 3px;
border-width: 2px;
border-style: outset;
border-color: buttonface;
padding: 1px 6px;
text-rendering: auto;
color: initial;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
margin: 0em 0em 0em 0em;
font: 13.3333px Arial;
}
I'm designing a responsive site which means the layout changes. When viewed as wide as possible, my blockquote wraps to the next line. I would like for it to be on the same line.
I have managed to fix the open quote by adding some text-indent however I'm unable to move the close quote.
My HTML:
<blockquote><p class="blockQuote">In recent years we have noticed a growth in demand for audit services, by enterprises with foreign investment, partly because of the demands on the part of organizations such as the CPI and the central bank.</p></blockquote>
CSS:
blockquote {
font-family: serif;
font-style: italic;
color: #000;
margin: 0px 0px 10px 0px;
}
blockquote:before {
content: "\201C";
}
blockquote:after {
content: "\201D";
blockquote:before {
position: absolute;
width: 60px;
height: 60px;
line-height: 1;
font-size: 120px;
}
blockquote:after {
position: absolute;
width: 60px;
height: 60px;
line-height: 1;
font-size: 120px;
}
When I use a span element, the close quote fixes but the open quote looks like it should move further up.
Add <span> tag instead of <p> tag. Working JSFiddle here https://jsfiddle.net/jfmf4ujc/
I have a simple text input and a select list. I'm styling them in a similar way and I need them to have the same text-indent.
If I set the text indent to a px value then they both indent the same amount on my iPhone, however they are different in Chrome. Is there a way of standardizing this cross device and browser?
http://codepen.io/anon/pen/pnvqJ
<input placeholder="Last name" type="text" maxlength="25" name="last_name" size="60" value="" >
<select name="title">
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select>
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
input, select {
display: block;
border: none;
text-indent: 10px;
width: 100%;
background: grey;
}
Just format them separately use one style for select other for input
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
select {
display: block;
border: none;
text-indent: 10px;
width: 100%;
background: grey;
}
input{
display: block;
border: none;
width: 100%;
background: grey;
text-indent:15px;
}
If it's important to you keep one class for both (which will have a lot of styling inside you can do simply like that
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
input, select {
display: block;
border: none;
text-indent: 10px;
width: 100%;
background: grey;
}
input{
text-indent:15px !IMPORTANT;
}
which basically does the same in this instance. !IMPORTANT means that it will be used even if in other style tag it's already with other value. result in both ways is the same ()
It seems that the select has an inherent minimal indentation of the width of . Have you considered figuring out the pixel width of NBSP and setting it to be the text-indent of the input in JS?
I am not good in designing, still applied some logic,
Just add one more class,
select {
text-indent: 5px !important;
}
Example
I think select element takes more extra indent by default, that is what casing issue, if you are facing this issue only for specific browser, please try to apply this class for those specific browsers only.