Is there a way I can get the full href attribute (https://studyacer.com/question/audit-and-assurance-services-444592) instead of a partial href? (https://studyacer.com/question/audit-and-) from this markup?
<td class="word-break">
<span class="label label-success">Due in 5 days</span>
<a href="https://studyacer.com/question/hey-greg-here-is-my-hrm522-discussion-444593">
<strong>hey Greg here is my HRM522 discussion</strong></a>
<small>"Auditing of Organizational Ethics and Compliance Programs" Please respond to the following:...
</small>
<br />
<strong>Business > Management</strong>
</td>
The XPath expression I have is this '//td[#class="word-break"]/a/#href' and it's just giving me a partial url.
The site uses absolute urls (if that helps).
Edit: I am using Scrapy to implement a basic crawler. When I run
response.xpath('//td[#class="word-break"]/a/#href')
I get the partial url.
For anyone with a similar issue. Turns out that running
response.xpath('xpath_expression')
gives you a partial url in Scrapy. Especially if the url is a long one.
For the full value use extract() at the end. Like this
response.xpath('xpath_expression').extract()
Related
Using Razor I have a page I want to put an anchor whose linktext includes markup.
for example:
<div>Line1<div>
I tried the following code:
#Html.ActionLink(#Html.Raw("<div>") + "Create New" + #Html.Raw("</div>"), "Create")
but it didn't work.
I know that this might look a bit odd. But is it possible to do that in MVC?
No, it's not possible. However, you can create a new HTML helper method for this. It should be pretty straight forward to do so. If not you can use URL.Action link.
<a href="#Url.Action("Action", "Controller")">
<div> Create New </div>
</a>
I have been using Jekyll for a month or two now, I am also new to Ruby so learning every day.
In my site I want to add the reading time of blog posts, I have found this ruby gem which will let me do it
https://github.com/garethrees/readingtime
I install it in the normal way into my sites root and add the code needed and nothing happens. This isn't a shock because I have no actually link to it in my sites root?
So it my site looks like this html wise
---
layout: default
---
<div class="twelve columns">
<h3>{{ page.title }}</h3>
<span class="date">Wrote by Josh Hornby</span>
<span class="date">Estimated reading time – <%= #article.body.reading_time %> </span>
<br /> <br />
<%= #article.body %>
{{ content }}
</article>
<div class="twitter_button"> <img src="/images/twitter.png" alt="twitter-logo" width="50" height="50" /> </div>
</div>
<div class="four columns">
<h3>Recent Posts</h3>
<p>Find out what else I've been talking about:</p>
{% for post in site.related_posts limit: 10 %}
<ul class="square">
<li><a class="title" style="text-decoration:none;" href="{{post.url}}"><strong>{{ post.title }}</strong></a>
{% endfor %}
</ul>
</div>
Now I'm not shocked that its not working but my question is how to a install the gem so I can access it in my Jekyll file? Do I need to create a _plugin directory and call it from there? Or won't it work as its not a jekyll plugin? In that case I may have a little project writing my own Ruby Jekyll plugin.
As you have surmised, you cannot call arbitrary ruby commands in your html using <%. Instead, you want to write a plugin which defines a Liquid filter. In your html above, you would use the liquid tag to grab the content of the page. You might want to brush up on liquid-for-designers and liquid-for-programmers as well as the Jekyll notes on writing liquid extensions before we dive in, but I'll try to explain.
First, we need to use a Jekyll filter to grab the content of the page, which we will pass to our plugin for analysis. Above you have an #article.body which probably means something to a ruby on rails site, but doesn't mean anything to Jekyll. As you see in the center of your layout file, the content for the page is simply called content. It is pulled in through a Liquid output, indicated by the {{ }}.
In place of the line
<span class="date">Estimated reading time – <%= #article.body.reading_time %> </span>
We want a line that grabs the content and passes it to our plugin:
<span class="date">Estimated reading time – {{ content | readingtime }} </span>
The vertical bar is a filter, meaning pipe content to the function readingtime and include the output. Now we need to write the plugin itself. In the _plugins directory, we create a ruby script following the standard template for a Liquid filter:
require 'readingtime'
module TextFilter
def readingtime(input)
input.reading_time
end
end
Liquid::Template.register_filter(TextFilter)
And save the above as something like readingtime.rb in _plugins. It's kinda self explanatory, but you see this tells ruby to load the gem, and define a filter that takes its input and applies the reading_time function to that string.
A little note: content will pull in the HTML version of the content, not a plain text string. I don't know if the readingtime gem needs a plain text string, but you can of course convert between them using a little extra ruby code. If necessary, that's left as an exercise to the reader (though this might help).
I'd like to have a classic ASP page that works similar to a jsfiddle except for VBscript this time. In other words, I need to display the output of vbscript code that is passed from one form to a page using POST.
Obviously, response.write(request.form()) doesn't work and I don't even know how if it's possible. I can see how a script could write the form input into a separate .asp page (using filesystemobject and writeline) which is then loaded, but is there a more elegant way as to not have a temporary page for each request?
You can do this using the execute() function (not to be confused with server.execute()).
Here is an example:
<%
if request.QueryString("task") = "execute" then
Response.Write "Output: <hr />"
Execute(Request.Form("VbScript"))
Response.Write "<hr />"
end if
%>
<form action="test.asp?task=execute" method="post">
<textarea name="VbScript" style="height: 100px">
x = 4 - 3
response.write x
</textarea>
<input type="submit" value="Execute" />
</form>
However, whilst this is fun, i cant think of a single use where security wouldnt be a major concern.
Your essentially giving the user full access to your server!
I have a Document Type, that has a tab with some properties.
The properties are Upload types, and Simple Editor types.
(Users are supposed to upload images with some image text).
I have not grouped the "Upload" and "Simple Editor" properties, so how do i do this?
Next question,
I want to loop through each group (there should be 3 currently) and display them on my website.
The markup should look like the following:
<div>
<img src="PATH-TO-UPLOAD-TYPE" />
<div>"TEXT FROM SIMPLE EDTIOR TYPE"</div>
</div>
..
<div>
<img src="PATH-TO-UPLOAD-TYPE" />
<div>"TEXT FROM SIMPLE EDTIOR TYPE"</div>
</div>
...
I would like to use Razor for this. Thanks in advance!
For the first part, using the Razor model, you can't. The content object that you get on the front end only contains the properties, the tabs are not included, as they're only really for organising things in the back office.
You CAN get that information using the Umbraco API, but it's pretty database intensive and could potentially be quite slow if you have a lot of properties/tabs.
You'd be better grouping them yourself in your Razor Macro.
for the second part, you can acces the properties of a page via #Model.property. For example:
<div>
<div>#Model.simpleProperty</div>
</div>
I tried figuring it out as well as google for answer, but it still does not work.
Basically in my Details.cshtml, this code: #Html.DisplayFor(model => model.eLink) is generating a URL link out (eg. http://www.w3schools.com) out from the database based on the id no.
However, I need this URL link to come out in a iframe. How do I incorporate this code:
#Html.DisplayFor(model => model.eLink)
to here?
The purpose of Html.DisplayFor is to display the value of a property of your view as text. It is not its job to put it in an iframe. it is not what you need to use.
You wrote the html that you seek. So just use your model.eLink in the iframe:
<iframe src="#Model.eLink"; width="1000" height="300" scrolling="no"></iframe>