How do i dynamically set the parameter value for selectLink() in Goutte? - goutte

How to click on a link dynamically using Goutte php web scraping library? Whatever example that has been shared on net they have only hard coded ('Plugins') the value as in the example below
$link = $crawler->selectLink('Plugins')->link();
How do i dynamically set the parameter value for selectLink()?

Are you looking for
$text = 'someAnchorText';
$link $crawler->selectLink($text)->link();
?

Related

Handle POST data sent as array

I have an html form which sends a hidden field and a radio button with the same name.
This allows people to submit the form without picking from the list (but records a zero answer).
When the user does select a radio button, the form posts BOTH the hidden value and the selected value.
I'd like to write a perl function to convert the POST data to a hash. The following works for standard text boxes etc.
#!/usr/bin/perl
use CGI qw(:standard);
sub GetForm{
%form;
foreach my $p (param()) {
$form{$p} = param($p);
}
return %form;
}
However when faced with two form inputs with the same name it just returns the first one (ie the hidden one)
I can see that the inputs are included in the POST header as an array but I don't know how to process them.
I'm working with legacy code so I can't change the form unfortunately!
Is there a way to do this?
I have an html form which sends a hidden field and a radio button with
the same name.
This allows people to submit the form without picking from the list
(but records a zero answer).
That's an odd approach. It would be easier to leave the hidden input out and treat the absence of the data as a zero answer.
However, if you want to stick to your approach, read the documentation for the CGI module.
Specifically, the documentation for param:
When calling param() If the parameter is multivalued (e.g. from multiple selections in a scrolling list), you can ask to receive an array. Otherwise the method will return the first value.
Thus:
$form{$p} = [ param($p) ];
However, you do seem to be reinventing the wheel. There is a built-in method to get a hash of all paramaters:
$form = $CGI->new->Vars
That said, the documentation also says:
CGI.pm is no longer considered good practice for developing web applications, including quick prototyping and small web scripts. There are far better, cleaner, quicker, easier, safer, more scalable, more extensible, more modern alternatives available at this point in time. These will be documented with CGI::Alternatives.
So you should migrate away from this anyway.
Replace
$form{$p} = param($p); # Value of first field named $p
with
$form{$p} = ( multi_param($p) )[-1]; # Value of last field named $p
or
$form{$p} = ( grep length, multi_param($p) )[-1]; # Value of last field named $p
# that has a non-blank value

How to get general link field properties in Sitecore Powershell Extensions

Using SPE (Sitecore Powershell Extensions) I need an Item's general link type field "Url" property, but have been running into problems converting the type.
I've tried to convert Item property to Linkfield object like this:
[Sitecore.Data.Fields.LinkField]$field = $myolditem["Email"]
Output:
Error converting string to Linkfield
How do I convert the string value of the field to a Linkfield type using SPE?
Try using
[Sitecore.Data.Fields.LinkField]$field = $myolditem.Fields["Email"]
$Url = $field.Url
You should get the Url of the Link
There are different types of Links : Internal, External, Media Links etc.
In case if you want to retrieve URLs irrespective of link types, please use the below lines..
[Sitecore.Xml.Xsl.LinkUrl]$fieldLink = New-Object -TypeName 'Sitecore.Xml.Xsl.LinkUrl'
$Url = $fieldLink.GetUrl($myolditem, "Email")

Maximum Size of characters in Page Name in CQ5

when we are creating a page using Scaffolding it is only taking page name maximum 20 characters,is there any other way to override that validation? Thanks in advance....
In the default scaffolding, (/libs/wcm/scaffolding/components/scaffolding/body.jsp) on line 242 you see the following code:
var title = frm.findField("./jcr:content/jcr:title");
if (title) {
var hint = title.getValue();
if (hint) {
params[":nameHint"] = hint;
}
}
The main thing to take away from this code is params[":nameHint"]. This param is submitted when you create a page. The nameHint paramater is what causes the node name to be limited to x amount of characters. When nameHint is submitted, it runs through a filter which formats the name for JCR. This is done to ensure a valid JCR name. It is for your protection. You can read more about this in the Algorithm for Node Name Creation section on this page: http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html
To overwrite this problem, you would need to change params[":nameHint"] to params[":name"]. Just remember, that this won't ensure a valid JCR name. If this is a concern, you can always right some code to change the title to a valid JCR name and then set it to the :name param.
One other thing, I did read this - "when :nameHint is filtered it cuts the name to a configurable maximum length (default is 20 characters)". I cannot find how this is configured though.
Configure CQ POST servlet.. and you should be good

Using changestamp in GoogleDocs (null changestamp)

I am trying to find the max changestamp so I can start using it. I tried the following:
URL url = "https://docs.google.com/feeds/default/private/changes?v=3"
ChangelogFeed foo = service.getFeed(url, ChangelogFeed.class);
LargestChangestamp stamp = foo.getLargestChangestamp();
stamp is always null.
Is this the way to get the largest changestamp, or do I need to set it first in order to use it?
The largest changestamp is also available in the user metadata feed. See the "docs:largestChangestamp" element within the response protocol tab here,
I'm not sure the java api exposes the largestChangestamp property directly yet - last time I checked it was hidden in the xmlBlob property, and I had to do an xml parse to grab it out.
This seems to be a bug in the API. I got the changestamps by getting the ChangelogEntrys from the ChangelogFeed:
List<ChangelogEntry> entries = foo.getEntries();
for (ChangelogEntry entry: entries) {
String blob = entry.getXmlBlob().getBlob();
System.out.println("Blob: " + blob);
}
The changestamp for an entry is contained in its blob.

How can I use PowerShell to set the default document in IIS?

I'm configuring a web site using PowerShell and I want to set the default document. How do I do this?
This is one way:
$metabasePath = "IIS://Localhost/W3SVC"
$iisNumber = "12345"
$site = new-object
System.DirectoryServices.DirectoryEntry("$metabasePath/$iisNumber/root")
$site.psbase.Properties["DefaultDoc"].Value =
"newdefdoc.htm," + $site.psbase.Properties["DefaultDoc"].Value
$site.psbase.CommitChanges()
The value returned in $site.psbase.Properties["DefaultDoc"].Value is a comma separated list of documents so you may need to re-jig the order to suit your case. The example above just adds a new default document (newdefdoc.htm) to the top of the list.