Html Dom with jsoup - dom

I have this html code (part of a long html code) :
<div class="yt-lockup-content">
<h3 class="yt-lockup-ellipsize">
<a class="yt-uix-contextlink yt-uix-sessionlink yt-uix-tile-link result-item-translation-title"dir="ltr"title="Rihanna ft. Calvin Harris - We Found Love LYRICS"data-sessionlink="ved=CAoQvxs%3D&ei=CPLZjMDLwbICFUag3wod7Dm-pw%3D%3D"href="***/watch?v=1KzEu5hWmRY***">Rihanna ft. Calvin Harris - We Found Love LYRICS</a></h3><p class="description " dir="ltr">
<b>bla</b> ft. Calvin Harris -
<b>bla</b>
bla bla
<b>bla bla bla</b>
<b>...</b>
</p><div class="yt-lockup-meta">
<ul class="single-line-lego-list">
<li> <a href="/results?search_type=videos&search_query=rihanna+we+found+love&high_definition=1" class="yt-badge-std">HD
</a>
</h3>
And i want to get to this text : href=/watch?v=1KzEu5hWmRY (The bold text).
I know how to get the all line, but how can i grab this text ?
Thanks,
Or.

Here's an example:
String html = // your html here ...
Document doc = Jsoup.parse(html);
Element element = doc.select("h3[class=yt-lockup-ellipsize] > a").first();
String hrefLink = element.attr("href");
However if you want to parse a website, you should use Jsoup.connect("http://link.com").get() instead of Jsoup.parse(html)

Related

Umbraco 8 how to line break in textareaEditor

When using Umbraco textarea, I need to have multiple lines with the <br/> tag
code is here
var subTitle = item.Value("sliderSubTitle");
and html code is
div>
#subTitle
</div>
but data comes in single line
Can you check this?
<div>
#Html.Raw(subTitle.Replace("\n", "<br />"))
</div>

Autohotkey: Replace a text with an icon

How can I replace a text with icon, just as a starter replacing (y) with a thumbs-up icon (like in FB)
So something like
(y)::.....
Your question is missing informations about the scenario where you're working in. Since you have mentioned 'Facebook' I believe you'll need Javascript instead of AutoHotKey. So, here's the two steps to switch letters by icons in a HTML page using Javascript. I hope it can enlighten your ideas:
1- Incorporate an icon library in your HTML's head like <link href="https://fonts.googleapis.com/icon?family=Material+Icon‌​s" rel="stylesheet"> (there's other options besides Google's one around the web)
2- Use Javascript to replace every expression like (Y) by the icon's library code such as <i class="material-icons">thumb_up</i>
Working snippet:
function replace(){
var box = document.getElementById('box');
var str = box.value;
var filterok = str.replace(/\(Y\)/gi, "<i class='material-icons'>thumb_up</i>");
var filtersmile= filterok.replace(/\=\)/gi, "<i class='material-icons'></i>");
var filterHHH= filtersmile.replace(/HHH/gi, "<i class='material-icons'>favorite</i>");
document.getElementById("target").innerHTML = filterHHH;
}
body {
background: lavender;
}
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body onload="javascript: replace()">
<textarea rows="4" cols="50" oninput="replace()" id=box>
Every (Y) and =) and HHH inserted here will be substituted by a match icon.
</textarea>
<br>
<span id=target></span>
</body>
ps: The g on StringReplace stands for 'global' while gi stands for 'global + case insensitive'.
ps2: The \ are used to scape the special chars used on the icons call.
ps3: Google Material Icons List
If you mean to use AutoHotKey to edit the HTML code of a webpage instead, the way to do the same as the example above with AutoHotKey instead of Javascript would be:
FileRead, filevar, page.html
symbolA:="(y)"
symbolB:="=)"
symbolC:="HHH"
StringReplace, filevar, filevar, %symbolA%, <i class='material-icons'>thumb_up</i>, All
StringReplace, filevar, filevar, %symbolB%, <i class='material-icons'></i>, All
StringReplace, filevar, filevar, %symbolC%, <i class='material-icons'>favorite</i>, All
FileDelete, page.html
FileAppend, %filevar%, page.html
return

Perl Scrappy select using class attribute

I was trying to scrape using Perl Scrappy. I would like to select html elements with class attribute using 'select'.
<p>
<h1>
<a href='http://test.com'>Test</a>
<a href='http://list.com'>List</a>
</h1>
</p>
<p class='parent-1'>
<h1>
<a class='child-1' href="http://sample.com">SampleLink</a>
<a class='child-2' href="http://list.com">List</a>
</h1>
</p>
I need to get element('a' tag) with class name 'child-1' which is a child nod of <p class='parent-1'> using select method.
I have tried like this
#!/usr/bin/perl
use Scrappy;
my $scraper = Scrappy->new;
$scraper->get($url);
$scraper->select('p a')->data;
But it will select the first 'p' tag also.
Could you please help me with this?
Bearing in mind choroba's warning, to select an <a> element with a class of child-1 that is a child of a <p> element with a class of parent-1 you would write
$scraper->select('p.parent-1 > a.child-1')
The problem is that in HTML, a <p> tag can't contain a <h1> tag. In fact, the HTML is parsed as
<p></p>
<h1>
<a href='http://test.com'>Test</a>
<a href='http://list.com'>List</a>
</h1>
<p class='parent-1'></p>
<h1>
<a class='child-1' href="http://sample.com">SampleLink</a>
<a class='child-2' href="http://list.com">List</a>
</h1>

How to define the link of footer bar icons? HTML iPhone App

Here is the code of my HTML iPhone app: http://summerblast.pt/iphone/code.html
I would like the icons of the bar to have a link. Lets say the first btn called "Emissão" will redirect to http://www.summerblast.pt/player.html
How can I do That?
Go to your ul tag with the id tabSelector and under it you'll find the li with each tab. Surrounding the contents of each li is a a tag. If you add href="[insert link to site here]", the contents of the li and therefor the icons will be clickable and link to the site.
An example of the edited tag would be this: <a data-bind="click: selectTab" href = "www.google.com"> Notice the href
Here would be the full contents of the li for the first icon:
<li data-bind="attr: {'data-tabid': TabId}" data-tabid="1263865">
<a data-bind="click: selectTab" href = "www.google.com">
<img data-bind="attr: {src: TabId == $root.CurrentTab().topLevelSectionID ? TABU.getImageUrl(SelectedTabIcon, $element) : TABU.getImageUrl(TabIcon, $element)}" src="http://myapp.is/image/aHR0cDovL3RhYi1iYXNlLXVybC50aGVhcHBidWlsZGVyLmNvbS9hcHBidWlsZGVyYXNzZXRzL2Fzc2V0cy90YWJiYXJfaWNvbnMvaW9zX3NlbGVjdGVkLzMyMC9SZXNpc3RvcnMucG5n/0/0">
<div data-bind="text: TabTitle">Emissão</div>
</a>
</li>

Text is not visible in IE6

I'm doing a site (asp.net mvc2) that should work in IE6 as well.
On a page I inject a control as partial view.
<div id="LocationContainer">
<% Html.RenderPartial("../Shared/EditTemplates/ContactInfoTemplate",
new ContextAwareViewModel<ContactInfoViewModel>()
{
ProcessStep = ProcessStep.Configure,
Model = Model.ContactPerson
}); %>
</div>
It contains following snippet of code:
<div style="margin-bottom: 10px;">
<%= Html.CheckBox(Model.Model.ContactType + ".IsDTBranch",
Model.Model.PersonViewModel.IsTDBranch,
new { #class = "tdBranchChkBox"}) %>
<%= Html.Resource("Resources, ThisIsTDBranchLabel") %>
</div>
That gives in the end this html:
<div style="margin-bottom: 10px;">
<input class="tdBranchChkBox" id="EventContact_IsDTBranch"
name="EventContact.IsDTBranch" type="checkbox" value="true" />
Il s'agit d'une succursale de la TD
</div>
After all of this IE6 doesn't render text. But text is there and appears when I start to select area where it should be.
Does anybody know how it can be cured?
Thanks.
Long story short:
In this case, a height correction seems to have done the trick. The Holly Hack involved adding the following code to the CSS file:
/* Hides from IE5-mac */
div#content
{
height: 1%;
}
/* End hide from IE5-mac / /— Holly Hack for IE 6 Peekaboo bug —*/
The explanation for this code can be found on the John and Holly website.
Taken from here http://www.bpwrap.com/2005/08/the-internet-explorer-6-peekaboo-bug/
Thanks a lot author.