PhantomJS only output part of the HTML [duplicate] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have 3 different files in my project and the layout is
phantomjs
-->phantomjs.js
-->phantomjs.exe
index.php
index.php:
$phantom_script = dirname(__FILE__). '\phantomjs\phantomjs.js';
$response = exec ('\phantomjs\phantomjs.exe' . $phantom_script);
echo $response;
phantomjs\phantomjs.js
var webPage = require('webpage');
var page = webPage.create();
page.open('http://www.google.com', function(status) {
console.log(page.content);
phantom.exit();
});

your usage oh phantomjs is correct according to the documentation.
http://phantomjs.org/api/webpage/property/content.html
php exec method returns the last line only.
Maybe that line is a white space.
http://php.net/manual/fr/function.exec.php
You shall have a seond parameter &$output, sent by reference. It is an array containing the entire output.
A problem you may face later, the content could need be to evaluated before you try to read it s DOM document content. Using for example innerHTML of HTML tag, ie: $('html').html();
If the page does not have jquery, you may include it, see this example, https://github.com/ariya/phantomjs/blob/master/examples/phantomwebintro.js
Note also that google may actively desire to not let users scrap and save their search results. Not sure about that.

Related

How to run specific code javascript DOM in page at site [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I want help please :(
I have several dom codes, in a js file, running on a site
site.com/script.js
I want to customize a specific code, to work only on a sub-page in the site.
for example:
the codes work on site.com
and I want a specific code that works
only on the site.com/page16
and code javascript just run by one file
I dont have any access to html page
You can access the end part of your url by using window.location.pathname.
For the website site.com/page16 - window.location.pathname returns the string "/page16".
Next you could have a function that checks to see what the current pathname is and terminates early if the pathname doesn't match /page16.
For example:
const subPageFn = () => {
// terminates early if subpage doesn't match page16
if (window.location.pathname !== '/page16') {
return
}
// runs page16 specific code here...
}
Then you'd call the function in any page by using
subPageFn()

How to call php script using jquery and terminate jquery script? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to execute a PHP script using jQuery and terminate jQuery at that point itself. I want the PHP script to be the last page on my browser rather than the jQuery page. I looked it up but every answer included the variable 'data' in it which I don't need. I'm not fetching data from PHP. I want to directly jump from jQuery to PHP and then end the program on the PHP file itself (I don't want to go back to the jQuery page to return some value from the PHP program). How can I do this?
I assume what you want to do is switch to the page ending .php instead of carrying out an ajax request to it and using the result. That doesn't require jquery and is simply done by setting globalThis.location or its href property like one of the following:
location = 'adjacent_file.php'
location.href = '/from/root/distant_file.php'
window.location.href = 'https://some.site/path/specific_file.php'
window.location = '... like the others ...'
Which of the above you pick is up to your needs and variable scope, but setting window.location will probably do you fine.
If you want to make a POST request that lands on the target page, there are a number of good answers already available for this other question - but you will need to create a form through vanilla JS or jquery and then submit it against the target page.

Markdown - PHP parser [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Do you know about some markdown PHP parser, with code highlight, etc, like the GitHub markdown parser or https://stackedit.io/editor?
If it is available via Composer then better.
I've tried:
https://packagist.org/packages/michelf/php-markdown
https://packagist.org/packages/league/commonmark
https://packagist.org/packages/erusev/parsedown
but the result of all these are almost plain text.
The best result belongs to michelf/php-markdown as you can see on the following image:
$ composer require michelf/php-markdown
---
use Michelf\MarkdownExtra;
$parser = new MarkdownExtra();
$html = $parser->transform($markdown);
echo $html;
[EDIT 1]
Now I'm almost at my goal.
I used:
https://github.com/sindresorhus/github-markdown-css
And now I get a result very similar to GitHub but the code is not getting highlighted (with colors) according the corresponded language (on this case: html) as you can see on the following image:
Then my QUESTION now is:
what extra step do I need to do in order to get code syntax highlight like GitHub does?. Please, check the following GitHub's output:
I guess you are missing CSS styles for the rendered HTML.
The generated HTML looks actually ok.
Try to include the styles in the document where you echo the $html.
For example use Github styles like this:
https://github.com/sindresorhus/github-markdown-css

How can I get the web page size programmatically? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there a way to get web page size using php or javascript ?
I want to do this for 100s of domain.
Edit
I am not sure what it means
Thanks
if you don't need the page don't use file_get_contents() you transfer the whole file for nothing.
instead use
get_headers ( string $url [, int $format = 0 ] )
then just extract the Content-Length
UPDATE- for checking if its changed use the above then compare Last-Modified
You could use file_get_contents() and then simply read the byte size of the result. There are also online tools which you can make a use of their APIs.
Also note, file_get_content() will simply get the content of the webpage as string, that is being said, if you are wanting to get the size including images and etc then you can use something like http://php.net/manual/en/function.stream-get-contents.php

How to get access to cross domain content? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Two webpages, http://website.com/home.php and another one is on my dropbox http://dropbox.com/myId/public/myfile.html.
I want to run a user script (which will be given out to other people) on home.php with some values, basically some 9-10 numbers. These values are already defined in the script. But they have to get updated on a regular interval, this is done by the user clicking a link or something. These updated values will be on myfile.html. I have full control over this file.
I have tried using localStorage in the script but that doesn't allow to share content over different domains. iframe also doesn't work due to cross domain. But is there a way that these values can be released by a function() on need.html when the iframe loads on home.php?
I'm pretty new to javascript, so I don't know everything.
What you need is JSONP. Here is more on that
I found out how to do it:
I created a script element using the userscript in home.php which links to need.js instead of need.html.
need.js contains code to add the "values" to localStorage.

Categories

Resources