Error while invoking screen-scraper via PHP
1. We tried to invoke the scrapes via PHP and it throws the following error
Error: Scraping session was either invalid or has not been set.
We are using the following code to invoke the scrapes via PHP
require_once('remote_scraping_session.php');
$return1=$object = new RemoteScrapingSession;
$return2=$object->initialize("scrapping session name");
$return3=$object->scrape();
if( $object->isError() )
{
echo "Error: " . $object->getErrorMessage() . "
";
die;
}
$data_set = $object->getVariable("scrapping session name");
$object->disconnect();
2. We have run the same scrapes through screen-scraper workbench and it runs succesfully and entries starts coming into our DB.
Please help us in resolving us the same ASAP.
The same error is coming !
We are getting the same error even after changing the site.com to scrapping session name.
Please advice us in detail on this and do inform us in case you need any details from us in resolving this.
Note: We are using Linux OS
Usually this happens when the
Usually this happens when the name on that third line of yours is not matching up to a session. Make sure it's the scraping session's name, and not the URL to the site you're scraping. Your example's line 3 isn't perfectly clear for me to know which one you're actual code is referencing.
On the second to last line in the example, you're requesting a variable named "site.com" from your session. If your session is not saving a variable named as such, this isn't going to return anything useful. It will, however, return good data if you give it a variable name that you've saved along the scraping process.
So.. those lines could look like this, for instance:
$return2=$object->initialize("My scraping session name");
...
$data_set = $object->getVariable("VARIABLE_I_SAVED");
Tim
Error still not re-solved
We are getting the same error even after changing the site.com to scrapping session name.
Please advice us in detail on this and do inform us in case you need any details from us in resolving this.
Note: We are using Linux OS
The problem is that the info
The problem is that the info you're initializing with does not match up with the actual settings of screen-scraper.
I just ran a test with the following:
Scraping session:
name: "! Test"
scrapable file goes to "http://www.google.com/"
That's all.
PHP: (Note that my server is running on a non-standard port, 38778)
<?php
require_once('remote_scraping_session.php');
$object = new RemoteScrapingSession;
$object->initialize("! Test", "127.0.0.1", 38778);
$object->scrape();
if ($object->isError())
echo "Error: " . $object->getErrorMessage();
else
echo "Done";
$object->disconnect();
?>
When I run the PHP, my message is "Done", as expected. As soon as I misspell "! Test", I get the message you have said you see. For example, I get your same error when I change "! Test" to "!@#QWEFA" or "! Teeeeest".
One way or another, somehow your scrape name is not correct. I would directly copy and paste it out of your screen-scraper workbench.
Because you're getting the message at all, it tells me that your port number is correct, and therefore your hostname is correct. It's just the scrape name that needs to be adjusted. Ensure that it is imported correctly into this installation of screen-scraper.
Hope that helps,
Tim