I am learning scraping using the PHP Simple HTML DOM Parser and Xpath. Accroding to the changelog given here http://sourceforge.net/news/?group_id=218559. The PHP SImple HTML DOM Parser supports xpath generated from Firebug. But I am not able to figure out how to use it. Can anyone show me an example of the same...
The find function.
http://simplehtmldom.sourceforge.net/manual.htm#section_find
$content = file_get_html($link);
$elems = $content->find("/html/body/div/div");
There's find function in Simple HTML DOM Parser. BUT it accepts selectors!
So you cant just write
$html = file_get_html($link);
$elements = $html->find("/html/body/div/p");
because then you'll get more than one element!
to get just exact element marked by XPath, write
$element = $html->find("/html/body/div[1]/p[1]", 0);
Related
I am trying to get the xpath and click that particular xpath, but xpath keeps on varying(dynamic) like below
//*[#id="slipstream_action_bar_widget599"]/dl/dd[2]/span/span/svg
//*[#id="slipstream_action_bar_widget414"]/dl/dd[2]/span/span/svg
I need your help to get the xpath on the fly and pass that
Please try xpath as copied below:
//*[contains(#id,"slipstream_action_bar_widget")]/dl/dd[2]/span/span/svg
I'm working in an angular app where the JSON documents i'm getting includes several object. But while fetching the posts contents it also includes the HTML tags (i.e <p>) inside my angular brackets {{}} the problem here is i want only the contents not the HTML tags. Either give me a solution to get rid of that or tell me how to use html tags inside {{<p> hello <p>}} . I want to get an output of angular to show the paragraphed "hello" instead of <p>hello<p>.
Give me a solution to ge an output as hello instead of <p>hello<p>
thanks in advance!
Thanks for the response!
I Used the angular binding ng-bind. That working fine for me. I've used
<p ng-bind-html="post.name"></p> . Now the problems solved :)
I'm not sure if there is a 'best practice' solution for this, I don't think angular is currently handling this. Try using a function that strips the html tags like this:
{{stripInput(inputObject)}}
stripInput(html) {
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
credit to this post. Some other good answers are there if this doesn't work :)
I have a custom Drupal 7 module that prints out the contents of a form, parses it and replaces all the form elements with equivalent divs, then prints out the HTML using DOMDocument().
This is then run through wkhtmltopdf to generate a PDF. I also have a little preg_replace that converts all occurrences of textarea/input to .div-textarea/.div-input in some inline CSS.
The issue, however, is that the default Drupal CSS files and the CSS files that are included in the custom theme are unable to be processed by this regex, because the drupal_get_css() function returns <link> tags and CSS's #import rule.
So the question is: do you know how I can get Drupal's theme output to print the actual raw contents of the CSS files in the HTML rather than these stylesheet links so that I can run the replacement function over it?
Or are there any better ways of copying CSS rules from one element/class to another?
I did this using a php funciton: file_get_contents
Then your code looks something like:
$css = file_get_contents(drupal_get_path('theme', 'my_theme') . 'css/my_css.css');
Then you can print that css in any template or append to any string to get your output.
Edit:
To get a list of all css files run: $css_list = drupal_add_css();
Once you have the CSS loaded as a string (see #danielson317's answer for a good example of how to do this) add to the head using drupal_add_html_head().
If you add the second key param, you can run your regex using hook_html_head_alter().
I am trying to load html file in CKEditor in asp.net but for some reason I don't know how to put the html code from the code behind file.
CKEditor1.FilebrowserBrowseUrl = url;
CKEditor1.BasePath = url;
CKEditor1.Text = content;
none of that helped
Any advice? Thanks in advance, Laziale
I'm not sure which version you are using, but let's suppose that it's 3.x. I was playing around with the control and didn't find any possible way of doing this from code behind. However, I managed to make it work like this:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "fckInitialization", #"
window.onload = function () {
var oEditor = CKEDITOR.instances['" + txtPost.ClientID + #"'];
oEditor.insertHtml('<strong>This is a bold text.</strong>');
};
", true);
I tried it in IE 8 and the last version of Mozilla (I think it was 9) and it worked. I also tried the same thing, but instead of window.onload I used the jQuery $(document).ready() and it worked only in IE. The reason is that you have to wait for everything to load in order to use the functions from the CKEditor API. I played with Firebug and the insertHTML worked.
If you are using 2.x, you can see somewhere in Google the same approach, but with a different API. I just can't find the link right now.
Another problem will be here, as you may figure out, that if you want to initialize a long text, you will have to write everything in a script, which is not really nice.
Maybe a possible solution for you will be to convert the HTML to BBCode first and then just set the Text property. This, of course, depends on the way you use the control, because BBCode does not contain all possible tags, but you can always modify the bbcode plugin of CKEditor to meet your needs. And I tested it and it works.
PS. Probably you can do it with the JavaScript method and an AJAX call.
Hope this helps!
Assuming ckeditor is being initialized from a textarea field, you can simply populate the body of the textarea.
I know that you can apply CSS in order to style objects in Flex using the StyleManager:
http://livedocs.adobe.com/flex/3/html/help.html?content=styles_07.html
You can also load compiled CSS files (SWFs) dynamically:
http://livedocs.adobe.com/flex/3/html/help.html?content=styles_10.html
However, I'm dynamically creating my CSS files using a web GUI and a server-side script.
If the CSS is changed, then the script would also need to compile the CSS into an SWF (which is not a viable option). Is there any way around this?
In this comment to an issue related to this in the Adobe bug tracker T. Busser is describing what might be a viable solution for you:
"I've created a small class that will 'parse' a CSS file read with an
HTTPService object. It takes apart the
string that is returned by the
HTTPService object, break it down into
selectors, and create a new
CSSStyleDeclaration object for each
selector that is found. Once all the
properties are assigned to the
CSSStyleDeclaration object it's added
to the StyleManager. It doesn't
perform any checks, you should make
sure the CSS file is well formed, but
it will be sufficient 99% of the time.
Stuff like #font, Embed() and
ClassReference() will hardly be used
by my customers. They do need the
ability to change colors and stuff
like that so they can easily theme the
Flex application to their house
style."
You could either try to contact this person for their solution or alternatively maybe use the code from this as3csslib project as a basis for writing something like what they're describing.
You can also implement dynamic stylesheet in flex like this . Here i found this article :
http://askmeflash.com/article_m.php?p=article&id=6
Edit: This solution does not work. All selectors that are taken out of the parser are converted to lowercase. This may work for your application but it will probably not...
I am leaving this answer here because it may help some people looking for a solution and warn others of the limitations of this method.
See my question: "Looking for CSS parser written in AS3" for a complete discussion but I found a CSS parser hidden inside the standard libraries. Here is how you can use it:
public function extractFromStyleSheet(css:String):void {
// Create a StyleSheet Object
var styleSheet:StyleSheet = new StyleSheet();
styleSheet.parseCSS(css);
// Iterate through the selector objects
var selectorNames:Array = styleSheet.styleNames;
for(var i:int=0; i<selectorNames.length; i++){
// Do something with each selector
trace("Selector: "+selelectorNames[i];
var properties:Object = styleSheet.getStyle(selectorNames[i]);
for (var property:String in properties){
// Do something with each property in the selector
trace("\t"+property+" -> "+properties[property]+"\n");
}
}
}
You can then apply the styles using:
cssStyle = new CSSStyleDeclaration();
cssStyle.setStyle("color", "<valid color>);
FlexGlobals.topLevelApplication.styleManager.setStyleDeclaration("Button", cssStyle, true);
The application of CSS in Flex is handled on the server side at compilation and not on the client side at run time.
I would see two options then for you (I'm not sure how practical either are):
Use a server side script to compile your CSS as a SWF then load them dynamically.
Parse a CSS Style sheet and use the setStyle functions in flex to apply the styles. An similar example to this approach is the Flex Style Explorer where you can check out the source.
Good luck.