Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
Alexa_Reviews=[]
for i in range(1,500):
link="https://www.amazon.in/Fire-TV-Stick-Alexa-Voice-Remote-3rd-Gen/product-reviews/B08R6QR863/ref=cm_cr_dp_d_show_all_btm?ie=UTF8&reviewerType=all_reviews"
page=requests.get(link)
soup=bs(page.content,'html.parser')
review= soup.find_all('span', class_="a-size-base review-text review-text-content")
for i in range(0,len(review)):
Alexa_Reviews.append(review[i].get_text())
You need to change URL to get next review page.
Now you are scraping 500 times the same page.
Be carefully amazon can ban you if you will do a lot of request in short time.
There you have some code:
from bs4 import BeautifulSoup
import requests
Alexa_Reviews = []
for i in range(1, 500):
link = "https://www.amazon.in/Fire-TV-Stick-Alexa-Voice-Remote-3rd-Gen/product-reviews/B08R6QR863/ref" \
"=cm_cr_getr_d_paging_btm_next_" + str(i) + "?ie=UTF8&reviewerType=all_reviews&pageNumber=" + str(i)
print(link)
page = requests.get(link)
soup = BeautifulSoup(page.content, 'html.parser')
review = soup.find_all('span', class_="a-size-base review-text review-text-content")
if review:
for y in range(0, len(review)):
Alexa_Reviews.append(review[y].get_text())
else:
break
I hope I have been able to help you.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
So I have this function:
library(worms)
library(dplyr)
worms_from_species_list<-function(file_name,file_location,header=T){
if(header==T){
setwd(file_location)
lista<-read_tsv(file_name)
names(lista)<-"Species"
worms_df<-wormsbynames(lista[,"Species"])
}else{
setwd(file_location)
lista<-read_tsv(file_name)
worms_df<-wormsbynames(lista)
}
worms_df<-worms_df%>%
mutate(new_name = ifelse(status=="unaccepted" & !is.na(status),valid_name,
ifelse(status=="accepted" & !is.na(status),name,name))
return(worms_df)
}
However, I can't even run it to begin with because it returns the following errors:
Error: unexpected ')' in:
" worms_df<-worms_df%>%
ifelse(status=="accepted" & !is.na(status),name,name))"
> }
Error: unexpected '}' in "}"
Does anyone have any idea what it might be?
Most IDEs provide paren-matching in some form. In this case, it suggests that you need to close out the mutate call.
In RStudio, for instance, when the cursor is to the right of name)), it indicates that the last right-paren on that line matches the left-paren of ifelse:
The | is the cursor, and the background-gray ( is the matching left-paren.
Similarly (though it's less commonly used), emacs/ess can show it if configured as such:
Here, both the right-paren and its matching left-paren are highlighted with a blue background.
Another trick in RStudio (and other IDEs) is to indent rows and see where they pan out. You'll see that I did that in before the first screenshot above, and you can see that it thinks return(worms_df) is within the mutate.
The solution looks like this:
worms_from_species_list<-function(file_name,file_location,header=T){
if(header==T){
setwd(file_location)
lista<-read_tsv(file_name)
names(lista)<-"Species"
worms_df<-wormsbynames(lista[,"Species"])
}else{
setwd(file_location)
lista<-read_tsv(file_name)
worms_df<-wormsbynames(lista)
}
worms_df<-worms_df%>%
mutate(new_name = ifelse(status=="unaccepted" & !is.na(status),valid_name,
ifelse(status=="accepted" & !is.na(status),name,name)))
return(worms_df)
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have a config.R file which has variable P.
P_val<-function(s){
if(s==1){
return(p<-0.01)
}
else if(s==2){
return(p<-0.031)
}
else if(s==3){
return(p<-0.001)
}
else if(s==4){
return(p<-0.021)
}
else if(s==5){
return(p<-0.1)
}
else if(s==6){
return(p<-0.77)
}
else if(s==7){
return(p<-0.35)
}
else if(s==8){
return(p<-0.66)
}
}
In my main.R file I want to use this P value but the thing is this p variable here is in a loop and I want different value for each loop run. I am showing you a sample demonstration of what I want:
d<-function(num){
for(s in seq(1,8,1)){
x=2*s ##some variable
source("config.R")
P_val(s)
reset(x,p)
}
reset<-function(x,p){
l_val= (x/p) * num
return(l_val)
}
}
I am using source("config.R") in my main.R file but I don't know how to use it as I am getting this error
Error in reset(x, p) : object 'p' not found
You have to assign the value p, like so:
p <- P_val(s)
More explanations on the files and relations between i and p might be helpful here.
Assuming there is a relation between the iteration number i and value of p you can try defining this relation as a function within the config.R file.
Then you just need to source("config.R") wihtin your main.R, as you're already doing, and make a call to the function from within the iterator whenever needed.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Please excuse my terrible knowledge of the language - just started looking at it a few hours ago.
I'm trying to understand this code and what it produces but quite unsure. Given that the value of inclusions is 10, why is the output what it is?
seps <- tapply(diff, nonCore, function(x) sort(x)[inclusions])
Outputs
"","x"
"ab",23
"ad",15
The value of diff is
"","x"
"1",31
"2",43
"3",37
"4",22
"5",27
"6",13
"7",24
"8",7
"9",26
"10",29
"11",2
"12",15
"13",10
"14",38
"15",23
"16",21
"17",46
"18",10
"19",20
"20",46
"21",20
"22",32
"23",26
"24",11
"25",16
"26",2
"27",13
"28",4
"29",15
"30",18
"31",13
"32",26
"33",1
"34",27
"35",12
"36",10
"37",35
"38",21
"39",9
"40",35
The value of nonCore is
"","x"
"1","ab"
"2","ab"
"3","ab"
"4","ab"
"5","ab"
"6","ab"
"7","ab"
"8","ab"
"9","ab"
"10","ab"
"11","ab"
"12","ab"
"13","ab"
"14","ab"
"15","ab"
"16","ab"
"17","ab"
"18","ab"
"19","ab"
"20","ab"
"21","ad"
"22","ad"
"23","ad"
"24","ad"
"25","ad"
"26","ad"
"27","ad"
"28","ad"
"29","ad"
"30","ad"
"31","ad"
"32","ad"
"33","ad"
"34","ad"
"35","ad"
"36","ad"
"37","ad"
"38","ad"
"39","ad"
"40","ad"
You should supply the code to construct the vectors diff and nonCore, as it is those who could help you need to do massive edits...
That said, what is happening is that your sorting the combination of the vectors according to ab and and ad. ab matches against the first 20 in diff and ad the last 20. Then you just subset the list that is created with the element number that is given by inclusion.
It's the same as running the function without [inclusion] and doing this afterwards:
sep[[1]][10]
sep[[2]][10]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I'd like to perform a mass renaming of all files in the lightroom database
From: xxx_2.nef
To : xxx.nef
I.e, for each image, if the name contains _2, then remove it.
Which tables and columns would be appropriate to hit?
Ended up using sql lite to open up the .lrcat file: Ran this query to fix the issue:
update AgLibraryFile
set basename = substr(basename, 0, length(basename) -1),
idx_filename = substr(basename, 0, length(basename) -1) || '.' || extension,
lc_idx_filename = substr(basename, 0, length(basename) -1) || '.' || extension,
originalFileName = substr(basename, 0, length(basename) -1) || '.' || extension
WHERE basename like '%-2'