I need to get a string in perl whose length is varying each day. Look at the URL content below
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /isos/preFCS5.3/LATESTGOODCVP</title>
</head>
<body>
<h1>Index of /isos/preFCS5.3/LATESTGOODCVP</h1>
<table><tr><th><img src="/icons/blank.gif" alt="[ICO]"></th><th>Name</th><th>Last modified</th><th>Size</th><th>Description</th></tr><tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td><td>Parent Directory</td><td> </td><td align="right"> - </td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td>CVP-LATEST-5.3.0.37.iso</td><td align="right">19-Jul-2011 03:32 </td><td align="right">816M</td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td>ChangeLog-LATEST.2011-07-19-03h.30m.01s</td><td align="right">19-Jul-2011 03:32 </td><td align="right"> 16K</td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td>is.iso</td><td align="right">19-Jul-2011 03:32 </td><td align="right">816M</td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td>md5SUM</td><td align="right">19-Jul-2011 03:32 </td><td align="right">111 </td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
<address>Apache/2.2.3 (Red Hat) Server at www.google.com Port 80</address>
</body></html>
You can see a string named "CVP-LATEST-5.3.0.37.iso".
I need to get that into $name.
the string CVP-LATEST-5.3.0.37.iso will keep on changing everyday
say CVP-LATEST-5.3.0.39.iso or CVP-LATEST-5.3.39a.iso or to CVP-LATEST-6.1.iso or CVP-LATEST-6.23.23.112.iso.
Is there any way I can get this ?
Here is the code
use strict;
use warnings;
use LWP::Simple;
my $oldVersion = CVP-LATEST-5.3.0.37.iso;
my $url = 'http://www.google.com/isos/preFCS5.3/LATESTGOODCVP/';
my $newPage = get($url)
or die "Cannot retrieve contents from $url\n";
if ( $newPage =~ /href=\"CVP-LATEST-5\.3\.0\.(\d\d)/ ) {
my $version = $1;
if ( $version != $oldVersion ) {
my $status = getstore($url . "CVP-LATEST-5.3.0.$version.iso",
"CVP-LATEST-5.3.0.$version.iso");
} else {
print "Already at most recent version\n";
}
} else {
die "Cannot find version tag in contents from $url\n";
}
Here if you see the code its getting only the number(xx) after 5.3.0."XX" and is of known length that is 2.
Is there anyway I can change it so that it will read the whole filename ie. CVP-LATEST-XXXXXX*.iso and then compare it with the $oldversion ?
Please note the string "CVP-LATEST-" and ".iso" remains constant, but later numbers change and can also contain alphabets.
Also note that there is one more file called is.iso in the URL content. I don't want to get that.
You should use a module that knows how to parse HTML when you want to parse HTML.
Your Question is Asked Frequently:
perldoc -q url
How do I extract URLs?
use HTML::SimpleLinkExtor;
...
my $extor = HTML::SimpleLinkExtor->new();
$extor->parse($newPage);
my($version) = grep /^CVP-LATEST-.*\.iso/, $extor->href;
Try
if ( $newPage =~ /href=\"CVP-LATEST-(.*?)\.iso\"/ ) {
my $name = "CVP-LATEST-${1}.iso";
$name contains the whole filename.
the secret to html regexes , not doublequote
/href="([^"]*)"/i
Related
I make a mini-project to reach a better level but I stuck here. Here is my code:
from bs4 import BeautifulSoup
import requests
html_from = requests.get("http://www.muhfak.hacettepe.edu.tr/tr/duyurular")
html_from.encoding = "UTF-8"
html_text = html_from.text
soup = BeautifulSoup(html_text, 'html.parser')
titles = soup.find_all("div", class_="liste")
print(titles[0])
I have to add "[0]" after the "titles" because the whole part is in a one-length list. I can see all the sections that I need in HTML codes. Is there a way to put each value in different list values?
When I make "titles[0].text", I can see the values I want. But "print(titles[0].a.text)" is not working and its output is only the latest value. How can I reach that values?
This is "titles[0].text" :
Yandal Başvurusu Hakkında 2022-01-05 15:00:00
2019/2020 - 2020/2021 Akademik Yıllarını Kapsayan Fakültemiz Faaliyet Raporu için Tıklayınız.
2021-12-14 08:00:00
13 Eylül 2021 Tarihinde Yapılan Mezuniyet Töreni Videosu için Tıklayınız. 2021-09-15 15:00:00
...
This is "titles[0].text" :
Yandal Başvurusu Hakkında
This is the part of the source and there are lots of "a" tags :
<script charset="utf-8" type="text/javascript">
$(document).ready(function() {
$('#duyurular_7').dataTable( {
"sPaginationType": "full_numbers",
"bStateSave": false,
"bSort": false,
"olanguage": {
"url": "//hu-iys.hacettepe.edu.tr/templates/template3/js/datatables_langs/tr.json"
}
} );
} );
</script>
<table class="table table-striped table-bordered" id="duyurular_7">
<thead>
<tr> <th>Başlık</th> </tr>
</thead>
<tbody>
<tr><td>Yandal Başvurusu Hakkında <span class="tarih">2022-01-05 15:00:00</span></td></tr>
<tr><td><a href="/tr/20192020_20202021_akademik_yil-184">2019/2020 - 2020/2021 Akademik Yıllarını Kapsayan Fakültemiz Faaliyet Raporu için Tıklayınız.
</a> <span class="tarih">2021-12-14 08:00:00</span></td></tr>
<tr><td>13 Eylül 2021 Tarihinde Yapılan Mezuniyet Töreni Videosu için Tıklayınız. <span class="tarih">2021-09-15 15:00:00</span></td></tr>
<tr><td>Fakültemiz Bölümlerinin Tanıtım Günleri İçin Tıklayınız. <span class="tarih">2021-08-06 10:00:00</span></td></tr>
<tr><td>2020-2021 Akademik Yılı Yandal Programı Sonuçları için tıklayınız. <span class="tarih">2020-10-02 11:00:00</span></td></tr>```
To get all <a> tags under tag with class="liste" you can use CSS selector ".liste a". For example:
import requests
from bs4 import BeautifulSoup
html_from = requests.get("http://www.muhfak.hacettepe.edu.tr/tr/duyurular")
html_from.encoding = "UTF-8"
html_text = html_from.text
soup = BeautifulSoup(html_text, "html.parser")
for a in soup.select(".liste a"):
print(a.get_text(strip=True))
print(a["href"])
print()
Prints:
Yandal Başvurusu Hakkında
/tr/yandal_basvurusu_hakkinda-177
2019/2020 - 2020/2021 Akademik Yıllarını Kapsayan Fakültemiz Faaliyet Raporu için Tıklayınız.
/tr/20192020_20202021_akademik_yil-184
13 Eylül 2021 Tarihinde Yapılan Mezuniyet Töreni Videosu için Tıklayınız.
https://www.youtube.com/watch?v=k55WKZAfmU8
Fakültemiz Bölümlerinin Tanıtım Günleri İçin Tıklayınız.
https://universitem.hacettepe.edu.tr/hayatin-butun-renkleri-burada-2/
...and so on.
In wsf, vbs and js files you can easily find out if they run elevated and if not you can easily make them.
The code I've written for that is this:
EnsureElevatedPrivileges();
WScript.Echo("Running elevated now!");
function EnsureElevatedPrivileges() {
if (!WScript.Arguments.Named.Exists("elevate")) {
new ActiveXObject("Shell.Application").ShellExecute(WScript.FullName, "\"" + WScript.ScriptFullName + "\" /elevate", "", "runas", 1);
WScript.Quit();
}
}
But this doesn't work in HTA files because the global WScript variable doesn't exist there.
So how can I force a specific HTA file run (itself) as admin?
You can take a look at this : Procedure to run HTA elevated
<html>
<head>
<title>HTA Helpomatic</title>
<HTA:APPLICATION
ID="oHTA"
APPLICATIONNAME="HTAHelpomatic"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
<!-- ID="objHTAHelpomatic" -->
<!-- WINDOWSTATE="maximize" -->
</head>
<SCRIPT Language="VBScript">
If HTAElevate() = True Then
CreateObject("WScript.Shell").Run "mmc.exe compmgmt.msc", , True
Call Main()
End If
Sub Main()
MsgBox "HTA-Ende", 4096
End Sub
'*** v13.3 *** www.dieseyer.de *****************************
Function HTAElevate()
'***********************************************************
' Unter Windows x64 laufen VBS' nach einem Doppelklick in der x64-Umgebung
' mit %WinDi%\System32\wscript.exe oder mit %WinDi%\System32\cscript.exe.
' In der x64-Umgebung laufen VBS aber nicht (richtig). Die Prozedur
' HTAElevate() erkennt dies und startet ggf. das VBS in der
Const Elev = " /elevated"
' MsgBox oHTA.commandLine, , "5016 :: "
' Trace32Log "5018 :: oHTA.commandLine: ==" & oHTA.commandLine & "==", 1
HTAElevate = True
' If InStr( LCase( oHTA.commandLine ), Elev) > 0 then MsgBox oHTA.commandLine, , "5022 :: "
If InStr( LCase( oHTA.commandLine ), Elev) > 0 then Exit Function
On Error Resume Next
window.resizeto 750, 10 ' : window.moveto screen.width / 2, screen.height / 2
On Error GoTo 0
' MsgBox oHTA.commandLine, , "5030 :: "
createobject("Shell.Application").ShellExecute "mshta.exe", oHTA.commandLine & Elev, "", "runas", 1
HTAElevate = False
self.close
End Function ' HTAElevate()
</SCRIPT>
<body>
</body>
</html>
<html>
<head>
<SCRIPT LANGUAGE="VBScript" use="to move window offscreen so that it should not flicker">
X=top.screenleft
Y=top.screentop
window.moveTo -2000,-2000
</SCRIPT>
<hta:application
ID="thisHta"
ApplicationName="The Great ManojBhakarPCM"
Border="thin"
BorderStyle="Static"
Caption="Yes"
ContextMenu="No"
MaximizeButton="No"
MinimizeButton="No"
Navigable="No"
Scroll="yes"
Selection="yes"
ShowInTaskbar="Yes"
SingleInstance="no"
SysMenu="Yes"
WindowState="normal"
>
<SCRIPT Language="VBScript" use="to Run As Administrator And window onload.">
If InStr(LCase(thisHta.commandLine), " /elevated") = 0 Then
createobject("Shell.Application").ShellExecute "mshta.exe", thisHta.commandLine & " /elevated", "", "runas", 4
self.close
else
window.moveTo X,Y
End If
Sub Window_OnLoad 'On window loading elements compeleted. start work here.
Document.body.innerHtml = "hello public, to kaise hai aap log? तो कैसे है आप लोग ?"
End Sub
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<style>
/* Author: ManojBhakarPCM */
body {
font-family: Arial, Helvetica, sans-serif;
}
.tile{/* Tile: width:vary, height: content wrap, padding: 5px;*/
height: auto !important;
padding:10px;
margin:3px;
display:inline-block;
}
.tilehead{
height: auto !important;
padding-left:10px;
padding-right:10px;
padding-top:2px;
padding-bottom:2px;
margin:2px;
font-size:10px;
display:inline-block;
}
/*-----COLORS----*/
.pink{background-color:#FF4081;color:white;}
.red{background-color:#D32F2F;color:white;}
.purple{background-color:#E040FB;color:white;}
.deeppurple{background-color:#512DA8;color:white;}
.indigo{background-color:#536DFE;color:white;}
.blue{background-color:#1976D2;color:white;}
.lightblue{background-color:#0288D1;color:white;}
.cyan{background-color:#00BCD4;color:white;}
.teal{background-color:#00796B;color:white;}
.green{background-color:#388E3C;color:white;}
.lime{background-color:#CDDC39;color:white;}
.yellow{background-color:#FFEB3B;color:white;}
.darkyellow{background-color:#FBC02D;color:white;}
.orange{background-color:#FF5722;color:white;}
.bluegray{background-color:#607D8B;color:white;}
.gray{background-color:#333;color:white;}
.roundcorner{border-radius:5px;}
.bold{font-weight:bold;}
.padmin{padding:5px;}
.padmid{padding:10px;}
.padfull{padding:15px;}
.inline{display:inline-block;}
/* --------CONTROLS---------*/
/*NAVBAR*/
.navbar {overflow: hidden;background-color: #333;padding:3px;text-decoration: none;}
.navbar a{padding:5px;font-size: 10px;text-decoration: none;}
.navbar a:hover{background-color:red;}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<body>
Hellow Worlds
</body>
</html>
I have created this hta templet and i use it very often. I belive that templets are best way to work with scripting etc. i usually keep uploaded these templets to websites so when working on any computer(which is not mine) can do work done just by downloading and start coding.
FEATURES:
Run as administrator
Does Not Flicker.
Don't Even Show Before getting admin prev.
Unicode support.
All HTA tags.
usefull classes of css for smooth UI
have a problem with translation is Symfony2.1
I tried almost all methods provided in the symfony_book but, only the translation from english to frensh that works, the reverse doesn't work
here is my routing.yml
_acceuil:
pattern: /{_locale}/acceuil/
defaults: { _controller: gestionConferenceApplicationBundle:acceuil:acceuil, _locale: en }
requirements:
_locale: en|fr|de
is my layout page I have thoses to links that allaw to switch between langage:
<a style="padding-top: -10px;" href="{{ path('_acceuil', {'_locale': 'fr' }) }}" >FRANCAIS</a>
<a style="padding-top: -10px;" href="{{ path('_acceuil', {'_locale': 'en' }) }}" >ANGLAIS</a>
and this line for test
{{ 'welcome in my site'|trans }}
and here is my messages.fr.xlf
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>welcome in my site</source>
<target>bienvenue dans mon site</target>
</trans-unit>
</body>
</file>
</xliff>
and here is my messages.en.xlf
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>bienvenue dans mon site</source>
<target>welcome in my site</target>
</trans-unit>
</body>
</file>
</xliff>
and here is the part wwe are interested in my config.yml :
framework:
#esi: ~
translator: { fallback: en }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: "%kernel.debug%"
form: true
csrf_protection: true
validation: { enable_annotations: true }
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
default_locale: en
trust_proxy_headers: false # Whether or not the Request object should trust proxy headers (X_FORWARDED_FOR/HTTP_CLIENT_IP)
session: ~
and when I run I have always :
bienvenue dans mon site
how can I achieve that
thank you in advance
I know why your translations don't work.
Because the translation source is still this same. It's string from your template.
So ex:
{{'My Trans'|trans()}}
messages catalogues shoudl look like this fr:
'My Trans': 'My trans FR'
and the en trans:
'My Trans': 'My trans EN'
I hope this example will help you.
How to run SpecFlow tests in OrchardCMS 1.4?
Steps:
Download OrchardCMS from here.
Run UsersFeature.ICanCreateANewUser() test. (WITHOUT BUILDING ALL SOLUTION!)
Result in Unit Test Sessions - Session window:
...
error: Unable to locate <input> name SiteName in page html:
<html>
<head>
<title>A 'script' named 'jQuery' could not be found.</title>
<style>
...
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>A 'script' named 'jQuery' could not be found.</i> </h2></span>
...
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<br><br>
<b> Exception Details: </b>System.InvalidOperationException: A 'script' named 'jQuery' could not be found.<br><br>
<b>Source Error:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
Line 259: throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "A '{1}' named '{0}' could not be found.", settings.Name, settings.Type));
Line 260: }
<font color=red>Line 261: ExpandDependencies(resource, settings, allResources);
</font>Line 262: }
Line 263: requiredResources = (from DictionaryEntry entry in allResources</pre></code>
</td>
</tr>
</table>
<br>
<b> Source File: </b> ...OrchardCMS_1.4\src\Orchard\UI\Resources\ResourceManager.cs<b> Line: </b> 261
<br><br>
<b>Stack Trace:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
[InvalidOperationException: A 'script' named 'jQuery' could not be found.]
Orchard.UI.Resources.ResourceManager.BuildRequiredResources(String resourceType) in F:\coding\zulatm\OrchardCMS_1.4\src\Orchard\UI\Resources\ResourceManager.cs:261
Orchard.Core.Shapes.CoreShapes.WriteResources(Object Display, TextWriter Output, String resourceType, Nullable`1 includeLocation, Nullable`1 excludeLocation) in F:\coding\zulatm\OrchardCMS_1.4\src\Orchard.Web\Core\Shapes\CoreShapes.cs:354
CallSite.Target(Closure , CallSite , CoreShapes , Object , TextWriter , String , ResourceLocation , Object ) +420
System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid6(CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) +1323
Orchard.Core.Shapes.CoreShapes.HeadScripts(Object Display, TextWriter Output) in F:\coding\zulatm\OrchardCMS_1.4\src\Orchard.Web\Core\Shapes\CoreShapes.cs:286
</body>
That is shown for every test case in SpecFlow I tried.
have you tried with a source enlistment rather than downloading the 1.4 release?
Didn't build all solution. Hence the Jquery module was not built and no JQuery script files there. Stupid mistake!
I want to run a script just ONCE by setting up a cron job using "at" command.
I'm using this now:
<?php
include "config.php";
if (isset($_POST['add']))
{
$sql = mysql_query("INSERT INTO {$table}(msg) VALUES('{$_POST['msg']}')");
if ($sql)
{
$cmd = "wget /var/www/index.php?id=" . mysql_insert_id() . " | sudo at " . $_POST['runat'];
exec($cmd);
echo exec("atq");
echo $cmd;
}
exit();
}
echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>";
echo "<input type='text' name='msg' />";
echo "<input type='text' name='runat' />";
echo "<input type='submit' name='add' />";
echo "</form>";
?>
However, this doesn't seem to be working. Am I doing this right? Or could you recommend something else?
You are using at command in wrong way. You need to echo command and pass it to at. Try it like that:
$cmd = "echo wget /var/www/index.php?id=" . mysql_insert_id() . " | sudo at " . $_POST['runat'];