根据以下代码,我必须得到一个虚拟的json响应,但它却向我显示错误。为什么?
<html>
<head></head>
<body>
<script>
var root = 'https://jsonplaceholder.typicode.com';
$.ajax({
url: root + '/posts/1',
method: 'GET'
}).then(function(data) {
console.log(data);
});
</script>
</body>
</html>
参考: https://jsonplaceholder.typicode.com/
提前致谢。
答案 0 :(得分:1)
错误是:
{&#34; message&#34;:&#34; Uncaught ReferenceError:$未定义&#34;,
&#34; filename&#34;:&#34; https://stacksnippets.net/js&#34;,&#34; lineno&#34;:17,&#34; colno&#34;: 1}
所以你需要像这样添加jquery作为脚本:
x<- c("RSelenium","rvest","plyr")
lapply(x, require, character.only = TRUE)
wdman::selenium(verbose = FALSE)
remDr <- remoteDriver(port = 4567L, browserName = "phantomjs")
remDr$open()
# Function to Get the phone number by Ad URL
get_ad_phoneNumber = function(ad_url){
# put the url as ID to match later with the data frame created previously
Id = ad_url
# go to the url
remDr$navigate(ad_url)
Sys.sleep(5) # wait until the page stop loading
# find the phone number's button
webElem <- remDr$findElement(using = 'css selector', value = 'aside > div >
div.box-grey-light.mbs.align-center > div > button')
Sys.sleep(5) # wait until the page stop loading
webElem$clickElement() # click on the the button
Sys.sleep(5) # wait until the page stop loading
#find the phone number after the click
webElem <- remDr$findElement(using = 'xpath', value =
'//aside/div/div[1]/div/span/a')
# extract the phone as a string character
phoneNumber=webElem$getElementText()
values = c(Id,phoneNumber)
# convert to data frame and add labels
mydf = as.data.frame(t(values))
names(mydf)= c("ID","PhoneNumber")
return(mydf)
}
您还可以查看jquery page