How to get the value of attributes - php

Having difficulties getting all the attributes of tags starting with <div id="test_num..."> from a page using Selenium Webdriver. Basically, I need to get all the values of ids that contain "test_num" from the following code
<body>
<div id="test_num_1" .....></div>
<div id="test_num_2" .....></div>
<div id="test_num_3" .....></div>
<div id="test_num_4" .....></div>
</body>
I have tried the following without any luck:
$allvalues=$driver->findElement(WebDriverBy::xpath('//*
[contains(#id,'test_num')]'));
Also tried using css-selector which didn't help.
Appreciate if somebody can point me to any information.

You need to take care of the quotes. Try the following :
$allvalues=$driver->findElements(WebDriverBy::xpath("//div[contains(#id,'test_num_')]"));

Related

Get content from WordPress to php

I've been trying to get information from WP for a while now and I still can't get it to work. What I'm trying to do is to get the information from an online resume and display it on the site.
The problem is that I haven't worked with WP a lot before and I can't figure out if there is a better way than SQL extraction to get that information.
This is the code I have now, it's very simple but doesn't work.
$output = '
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<div id="header">
<h1 class="title">'.the_custom_field('_candidate_name', 144).'</h1>
<ul class="contactInformation">
<li id="fullName">//This is where the name should go</li>
<li id="adress">//I want to fetch the adress and echo it here etc.</li>
<li id="phoneNumber"></li>
</ul>
<div id="resumePicture">
<img src="mVqghXM.jpg" height="auto" width="100px">
</div>
</div>
<div id="education">
<ul>
</ul>
</div>
<div id="experience">
</div>
</body>
</html>';
I've tried using get_custom_field as well as get_resume_field and placing them into a variable but i get an error that says it's undefined, and I presume that is because I don't have the WP Job Manager Field Editor plugin.
I would rather find another way to do this, either via some other WP compatible function or via SQL, instead of having to buy that plugin.
I would also love one of you to explain to me briefly how the WP system/database is built, because that would help immensely.
Thank you!
EDIT: I found the way of fetching the data from the database. It was get_resume_field, but what I'd done was copy the meta_key straight off the database, being "_candidate_name", but when I took the first underscore away, it worked. Thank you both for helping with the two problems I had. Cheers!
Use three files in your custom php file to get and use all wordpress function. Try this.
include_once("/path/to/wordpress/wp-config.php");
include_once("/path/to/wordpress/wp-load.php");
include_once("/path/to/wordpress/wp-includes/wp-db.php");
You have made to collect all the HTML into a single variable as per you need.
The major important thing is that you have to echo/ return the variable to print the output.
This will do the trick if you return it from a function
function get_page()
{
$output = '<p>Welcome</p>';
$output .= '<p>Again</p>';
return $output;
}
After the return you have to echo the statement by calling the function
$test = get_page();
echo $test;
Output:
Welcome
Again

Add <div> on a MediaWiki geshi syntax highlight extension

I use mediawiki to take note about the procedure that I follow, the source codes I write in mediawiki are highlighted with the expansion Genshi Syntax HighLight. I want to modify this expansion in mediawiki so it could be created a box above the source code in which it is written the programming language I used. I tried to see expansion sources in my mediawiki but I didn't find the segment in which is "sketch" the <div>. I also saw material about the creation of new expansion in mediawiki to understand how it runs, but I don't understand where the box is created.
I use syntax hightligher like this
some_code
and this is the result in html code generate from mediawiki
<div class="mw-geshi mw-code mw-content-ltr" dir="ltr">
<div class="bash source-bash">
<pre class="de1">
some_code
</pre>
</div>
</div>
I want to prepen the div to first div, like this
<div class='gsh-lang-label'>Language bash</div>
<div class="mw-geshi mw-code mw-content-ltr" dir="ltr">
<div class="bash source-bash">
<pre class="de1">
some_code
</pre>
</div>
</div>
Can you explain me if it is possible to do it and how can I face the problem?
I think ordinary jQuery will solve this problem. Something like:
$(".mw-geshi").each(function(){
$(this).before("<div class='gsh-lang-label'>" +
$(this).children().first().attr("class").split(' ')[0] +
"</div>")
})
Put this in [[MediaWiki:Common.js]], so this script will be run for every user.

MVC error including/excluding view

I have this situation.
Three 'section' elements, on each one i load a view
<section class="col-md-12 col-sm-6">
<?= $this->load->view('folder/view1',NULL,TRUE); ?>
</section>
<section class="col-md-12 col-sm-6">
<?= $this->load->view('folder/view2',NULL,TRUE); ?>
</section>
<section class="col-md-12 col-sm-6">
<?= $this->load->view('folder/view3',NULL,TRUE); ?>
</section>
I can delete, move or edit the view on top and the one on the bottom, but not the view in the middle, if I do so, the browser return me a blank page without errors.
I have enabled all error logs, there is nothing.
Every single view got their tags and php code perfectly idented and closed.
That one is the only one giving me troubles.
What could be the problem?
I would use firebug/ console to see if the view resource is found, or something else related to fetching the asset.
The three includes i´ve posted before are inside another one,
I save the view as cache, for this, I difined the result as a variable and send in to the browser.
$string=$this->load->view('main/mainview',$data,TRUE);
echo $string;
but i skiped an echo $string to send it to the browser, because the last parameter of load->view is false for default but in this way it must be TRUE
i´m still confused about what changes view2 does to avoid this parameter, but after solving it i can edit all file properly.
If someone considers this answer as useless i will delete it as fast as possible
Thanks for your time.

Getting unstyled text using QueryPath in PHP

I'm just getting to grips with QueryPath after using HTML Simple Dom for quite some time and am finding that the QP documentation doesn't seem to offer much in the way of examples for all of its functions.
At the moment I'm trying to retrieve some text from a HTML doc that doesn't make much use of ID's or Classes, so I'm a little outside of my comfort zone.
Here's the HTML:
<div class="blue-box">
<div class="top">
<h2><img src="pic.gif" alt="Advertise"></h2>
<p>Some uninteresting stuff</p>
<p>More stuff</p>
</div>
</div>
<div class="blue-box">
<div class="top">
<h2><img src="pic2.gif" alt="Location"></h2>
**I NEED THIS TEXT**
<div style="margin:stuff">
<img src="img3.gif">
</div>
</div>
</div>
I was thinking about selecting the class 'box-blue' as the starting point and then descending from there. The issue is that there could be any number of box-blue classes in the HTML doc.
Therefore I was thinking that maybe I should try to select the image with alt="Location" and then use ->next()->text() or something along those lines?
I've tried about 15 variations os far and none are getting the text I need.
Assistance most appreciated!
Can you have a look to this example http://jsfiddle.net/Pedro3M/mujtk/
I made like you said using the alt attribute, if you confirm if this is always unique
$("img[alt='Location']").parent().parent().text();
How about:
$doc->find('div.top:has(img[alt="Location"])')->text();

Get specific html content from other site with PHP

I want to try and get the latest movie I checked on the IcheckMovies site and display it on my website. I don't know how, I've read about php_get_contents() and then getting an element but the specific element I want is rather deep in the DOM-structure. Its in a div in a div in a list in a ...
So, this is the link I want to get my content from: http://www.icheckmovies.com/profiles/robinwatchesmovies and I want to get the first title of the movie in the list.
Thanks so much in advance!
EDIT:
So using the file_get_contents() method
<?php
$html = file_get_contents('http://www.icheckmovies.com/profiles/robinwatchesmovies/');
echo $html;
?>
I got this html output. Now, I just need to get 'Smashed' so the content of the href link inside the h3 inside a div inside a div inside a list. This is where I don't know how to get it.
...
<div class="span-7">
<h2>Checks</h2>
<ol class="itemList">
<li class="listItem listItemSmall listItemMovie movie">
<div class="listImage listImageCover">
<a class="dvdCoverSmall" title="View detailed information on Smashed (2012)" href="/movies/smashed/"></a>
<div class="coverImage" style="background: url(/var/covers/small/10/1097928.jpg);"></div>
</div>
<h3>
<a title="View detailed information on Smashed (2012)" href="/movies/smashed/">Smashed</a>
</h3>
<span class="info">6 days ago</span>
</li>
<li class="listItem listItemSmall listItemMovie movie">
<li class="listItem listItemSmall listItemMovie movie">
</ol>
<span>
</div>
...
There are some libraries which could help you!
One I've used for the same purpose, a long time ago, is this: http://simplehtmldom.sourceforge.net/
I hope it help you!
follow steps to achieve this
STEP1:-
First get the contents using file_get_contents in a php file
ex: getcontent.php
<?php
echo file_get_contents("http://www.icheckmovies.com/movies/checked/?user=robinwatchesmovies ");
?>
STEP2:-
CALL the above script using ajax call and add the content to a visibility hidden field in the html.
ex:
$('#hidden_div').html(response);
html:-
<html>
<body>
<div id='hidden_div' style='visibility:hidden'>
</div>
</body>
</html>
STEP3:-
now extract the id what ever you want.
What you are asking for is called as web scraping ,I have done this a few months back, the process goes like this,
Make a HttpRequest to the site from which you need the content,check
the php class for it
Use a DOM parse library for handling the downloaded page (it would be in html),simple HTLM DOM would be a good choice
Extract your required information
Here are some tutorials for you,
HTML Parsing and Screen Scraping with the Simple HTML DOM
Library
Beginning web page scraping with php
SO Posts:
HTML Scraping in Php
And best of all Google is your friend just search for "PHP scraping"

Categories