Phantomjs returns 404 in R when attempting webscraping










0














I am trying to collect some data from the OTC Markets (within the confines of their robots.txt) and I cannot connect to the webpage.



  1. The first step I tried was just to scrape the HTML right off the page, but the page requires javascript to load.

  2. So I downloaded phantomjs and connected that way. However, this leads to a 404 error page

  3. I then changed the user-agent to something resembling a user to see if it would let me connect and still, no luck! What is going on here

Here is a reproducible version of my code, any help would be appreciated. Phantomjs can be downloaded here: http://phantomjs.org/



library(rvest)
library(xml2)
library(V8)
# example website, I have no correlation to this stock
url <- 'https://www.otcmarkets.com/stock/YTROF/profile'

# create javascript file that phantomjs can process
writeLines(sprintf("var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page.open('%s', function ()
console.log(page.content); //page source
phantom.exit();
);", url), con="scrape.js")

html <- system("phantomjs.exe_PATH scrape.js", intern = TRUE)
page_html <- read_html(html)









share|improve this question





















  • backend.otcmarkets.com/otcapi/stock/trade/inside/… && backend.otcmarkets.com/otcapi/company/profile/full/… && backend.otcmarkets.com/otcapi/stock/trade/inside/… (Developer Tools is ur bff; those return lovely JSON; the parameters seem sane and repeatable with other stocks; i.e. you don't need any scary phantoms) + 👍 for checking 🤖
    – hrbrmstr
    Nov 12 '18 at 18:20











  • Woah! I didn't know that was even an option. I appreciate the help, should I leave the original up for an answer for this problem regardless? @hrbrmstr
    – RobertLD
    Nov 12 '18 at 18:22











  • totally up to you. This is a regularly occurring thing on SO (esp in the R tag). For some reason folks haven't picked up on async XHR requests yet.
    – hrbrmstr
    Nov 12 '18 at 18:25















0














I am trying to collect some data from the OTC Markets (within the confines of their robots.txt) and I cannot connect to the webpage.



  1. The first step I tried was just to scrape the HTML right off the page, but the page requires javascript to load.

  2. So I downloaded phantomjs and connected that way. However, this leads to a 404 error page

  3. I then changed the user-agent to something resembling a user to see if it would let me connect and still, no luck! What is going on here

Here is a reproducible version of my code, any help would be appreciated. Phantomjs can be downloaded here: http://phantomjs.org/



library(rvest)
library(xml2)
library(V8)
# example website, I have no correlation to this stock
url <- 'https://www.otcmarkets.com/stock/YTROF/profile'

# create javascript file that phantomjs can process
writeLines(sprintf("var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page.open('%s', function ()
console.log(page.content); //page source
phantom.exit();
);", url), con="scrape.js")

html <- system("phantomjs.exe_PATH scrape.js", intern = TRUE)
page_html <- read_html(html)









share|improve this question





















  • backend.otcmarkets.com/otcapi/stock/trade/inside/… && backend.otcmarkets.com/otcapi/company/profile/full/… && backend.otcmarkets.com/otcapi/stock/trade/inside/… (Developer Tools is ur bff; those return lovely JSON; the parameters seem sane and repeatable with other stocks; i.e. you don't need any scary phantoms) + 👍 for checking 🤖
    – hrbrmstr
    Nov 12 '18 at 18:20











  • Woah! I didn't know that was even an option. I appreciate the help, should I leave the original up for an answer for this problem regardless? @hrbrmstr
    – RobertLD
    Nov 12 '18 at 18:22











  • totally up to you. This is a regularly occurring thing on SO (esp in the R tag). For some reason folks haven't picked up on async XHR requests yet.
    – hrbrmstr
    Nov 12 '18 at 18:25













0












0








0







I am trying to collect some data from the OTC Markets (within the confines of their robots.txt) and I cannot connect to the webpage.



  1. The first step I tried was just to scrape the HTML right off the page, but the page requires javascript to load.

  2. So I downloaded phantomjs and connected that way. However, this leads to a 404 error page

  3. I then changed the user-agent to something resembling a user to see if it would let me connect and still, no luck! What is going on here

Here is a reproducible version of my code, any help would be appreciated. Phantomjs can be downloaded here: http://phantomjs.org/



library(rvest)
library(xml2)
library(V8)
# example website, I have no correlation to this stock
url <- 'https://www.otcmarkets.com/stock/YTROF/profile'

# create javascript file that phantomjs can process
writeLines(sprintf("var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page.open('%s', function ()
console.log(page.content); //page source
phantom.exit();
);", url), con="scrape.js")

html <- system("phantomjs.exe_PATH scrape.js", intern = TRUE)
page_html <- read_html(html)









share|improve this question













I am trying to collect some data from the OTC Markets (within the confines of their robots.txt) and I cannot connect to the webpage.



  1. The first step I tried was just to scrape the HTML right off the page, but the page requires javascript to load.

  2. So I downloaded phantomjs and connected that way. However, this leads to a 404 error page

  3. I then changed the user-agent to something resembling a user to see if it would let me connect and still, no luck! What is going on here

Here is a reproducible version of my code, any help would be appreciated. Phantomjs can be downloaded here: http://phantomjs.org/



library(rvest)
library(xml2)
library(V8)
# example website, I have no correlation to this stock
url <- 'https://www.otcmarkets.com/stock/YTROF/profile'

# create javascript file that phantomjs can process
writeLines(sprintf("var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page.open('%s', function ()
console.log(page.content); //page source
phantom.exit();
);", url), con="scrape.js")

html <- system("phantomjs.exe_PATH scrape.js", intern = TRUE)
page_html <- read_html(html)






r web-scraping phantomjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 18:11









RobertLD

112




112











  • backend.otcmarkets.com/otcapi/stock/trade/inside/… && backend.otcmarkets.com/otcapi/company/profile/full/… && backend.otcmarkets.com/otcapi/stock/trade/inside/… (Developer Tools is ur bff; those return lovely JSON; the parameters seem sane and repeatable with other stocks; i.e. you don't need any scary phantoms) + 👍 for checking 🤖
    – hrbrmstr
    Nov 12 '18 at 18:20











  • Woah! I didn't know that was even an option. I appreciate the help, should I leave the original up for an answer for this problem regardless? @hrbrmstr
    – RobertLD
    Nov 12 '18 at 18:22











  • totally up to you. This is a regularly occurring thing on SO (esp in the R tag). For some reason folks haven't picked up on async XHR requests yet.
    – hrbrmstr
    Nov 12 '18 at 18:25
















  • backend.otcmarkets.com/otcapi/stock/trade/inside/… && backend.otcmarkets.com/otcapi/company/profile/full/… && backend.otcmarkets.com/otcapi/stock/trade/inside/… (Developer Tools is ur bff; those return lovely JSON; the parameters seem sane and repeatable with other stocks; i.e. you don't need any scary phantoms) + 👍 for checking 🤖
    – hrbrmstr
    Nov 12 '18 at 18:20











  • Woah! I didn't know that was even an option. I appreciate the help, should I leave the original up for an answer for this problem regardless? @hrbrmstr
    – RobertLD
    Nov 12 '18 at 18:22











  • totally up to you. This is a regularly occurring thing on SO (esp in the R tag). For some reason folks haven't picked up on async XHR requests yet.
    – hrbrmstr
    Nov 12 '18 at 18:25















backend.otcmarkets.com/otcapi/stock/trade/inside/… && backend.otcmarkets.com/otcapi/company/profile/full/… && backend.otcmarkets.com/otcapi/stock/trade/inside/… (Developer Tools is ur bff; those return lovely JSON; the parameters seem sane and repeatable with other stocks; i.e. you don't need any scary phantoms) + 👍 for checking 🤖
– hrbrmstr
Nov 12 '18 at 18:20





backend.otcmarkets.com/otcapi/stock/trade/inside/… && backend.otcmarkets.com/otcapi/company/profile/full/… && backend.otcmarkets.com/otcapi/stock/trade/inside/… (Developer Tools is ur bff; those return lovely JSON; the parameters seem sane and repeatable with other stocks; i.e. you don't need any scary phantoms) + 👍 for checking 🤖
– hrbrmstr
Nov 12 '18 at 18:20













Woah! I didn't know that was even an option. I appreciate the help, should I leave the original up for an answer for this problem regardless? @hrbrmstr
– RobertLD
Nov 12 '18 at 18:22





Woah! I didn't know that was even an option. I appreciate the help, should I leave the original up for an answer for this problem regardless? @hrbrmstr
– RobertLD
Nov 12 '18 at 18:22













totally up to you. This is a regularly occurring thing on SO (esp in the R tag). For some reason folks haven't picked up on async XHR requests yet.
– hrbrmstr
Nov 12 '18 at 18:25




totally up to you. This is a regularly occurring thing on SO (esp in the R tag). For some reason folks haven't picked up on async XHR requests yet.
– hrbrmstr
Nov 12 '18 at 18:25












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267813%2fphantomjs-returns-404-in-r-when-attempting-webscraping%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267813%2fphantomjs-returns-404-in-r-when-attempting-webscraping%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto