Active3 years, 10 months ago

The big picture is to use Python to create a .txt file, then call the CasperJS script. Once the CasperJS script has run and saved its file (in this case the .png), have python grab that file and move to its next task.

Jan 16, 2016  🔴 Morning Jazz & Bossa Nova For Work & Study - Lounge Jazz Radio - Live Stream 24/7 Lounge Music 539 watching Live now.

  • Gzip 2 files into one file Why does Spain government want to increase minimum wage by such a large percentage at once? It's getting harder and harder not to offend anyone.
  • CasperJs loads json data from a local file. Way to load a local JSON file into a variable with CasperJs? That you have read our updated terms.
  • @@ -227,7 +227,7 @@ CasperJS can export the results of the test suite to a JSON file, which can be u $ casperjs test googletesting.js --jsonReporter=log.json You should get a JSON report like this.
  • 🔴 Morning Jazz & Bossa Nova For Work & Study - Lounge Jazz Radio - Live Stream 24/7 Lounge Music 539 watching Live now.
  • CasperJS can export the results of the test suite to a JSON file, which can be used to integration with various tools and services. To save the JSON log of your test suite, use the ``--jsonReporter`` option.
  • This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use.

As outlined in this question, another stack overflow question. I am looking primarily at the answer offered by Artjom B. towards the bottom. He suggests having Python save a .txt with the variables I would need, in my case (date, url) example, (2015-10-15, www.google.com)

I think part of my problem is I don't know much about JSON but I figure I would need to start by making both scripts, and then work on integrating them.

My Casper script is as follows:

I think that pretty much sums it up. Any direction on this is much appreciated, and any other links that you know of that can help me later down the road in running the Casper script inside a larger python script would be very helpful.

TLDR: How do I get CasperJS to read a text file, store the two values (date and url) as variables, and then use those variables to complete its job?

Community
Json
Mxracer888Mxracer888

1 Answer

JSON is very similar to plain JavaScript objects. Here is one:

You can directly require JSON in CasperJS (PhantomJS) like this:

Casperjs

And now you can use config.date and config.url in your script. You don't need assign those properties to dedicated variables, but of course you can do that to make the variables a little shorter:

Artjom B.Artjom B.
54.2k18 gold badges88 silver badges165 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Javascript Read Json File

Not the answer you're looking for? Browse other questions tagged pythonjsonphantomjscasperjs or ask your own question.