Looping through hyperlinks in a data frame - web-scraping

Looping through hyperlinks in a data frame
for link in df.iterrows():
driver.get(link[1]['profileUrl'])
src=driver.page_source
soup= BeautifulSoup(src,'html.parser')
exp_section=soup.find('section',{'id': 'experience-section'})
exp_section=exp_section.find('ul')
li_tags=exp_section.find('div')
a_tags= li_tags.find('a')
job_title=a_tags.find('h3').get_text().strip()
company_name=a_tags.find_all('p')[1].get_text().strip()
joining_date=a_tags.find_all('h4')[0].find_all('span')[1].get_text().strip()
exp=a_tags.find_all('h4')[1].find_all('span')[1].get_text().strip()
AttributeError: 'NoneType' object has no attribute 'find'

Related

I have a saved a excel file to RDS file but unable to view the same since it shows no data

I have a excel file which i saved into #saveRDS format but now when am trying to view the same i get "no data available in the table"
countries_all2 <- saveRDS(countries_map, "as_countries_map_2019.RDS")
summary(countries_all2)
Length Class Mode
0 NULL NULL
readRDS(countries_all2)
Error in readRDS(countries_all2) : bad 'file' argument
readRDS(countries_all2.RDS)
Error in readRDS(countries_all2.RDS) :
object 'countries_all2.RDS' not found
readRDS(as_countries_map_2019.RDS)
Error in readRDS(as_countries_map_2019.RDS) :
object 'as_countries_map_2019.RDS' not found
summary(countries_all2)
Length Class Mode
0 NULL NULL
You should not assign the result of saveRDS to the variable countries_all2.
saveRDS(countries_map, "as_countries_map_2019.RDS")
Then you need to quote the file name in readRDS. Assuming you want to read into the object countries_all2:
countries_all2 <- readRDS("as_countries_map_2019.RDS")

Getting Error "could not find function "assign<-" inside of colnames()

I'm using assign() to assign some new data frames from some other data frame. I then want to name some of the columns in the new data frame. When I use assign() to create the new data frames it works fine. But when I use the assign() inside of colnames() is gives the error 'Error "could not find function "assign<-".'
Here's my snippet of code(abbreviated of course):
for(i in 1:value) {
assign(Name[i], Old.Data.Frame[Old.Data.Frame$1 == Index[i]]) #I'm going to call this line of code 'New Data Frame' for brevity
for(j in 1:ncol(New Data Frame)) {
colnames(New Data Frame)[j] = as.character(Old.Data.Frame[3,j])
I do all this assign() stuff because the names of the Old Data Frame constantly change and I can create any concrete variables in my code, only the dimentions of the frame stay the same.
The only error in this code is that R cannot "find function assign<- in colnames(...". I'm flustered because assign() had just worked in the line before, any help is appreciated, thanks!
You have a list of variable names in Name, which you assign a value (your code block).
for(i in 1:value) { assign(Name[i], Old.Data.Frame[Old.Data.Frame$1 == Index[i]]) }
Could you then try (note I'm separating this code block for debugging purposes):
for(i in 1:value) { colnames(get(Names[i])) <- as.character(Old.Data.Frame[3,] }
get will retrieve the data (data.frame) assigned to the variable name Names[i] (character)

Not able to switch to frame using its previously found webelement with frame(Webelement)

On trying to switch frame 2 via frame(webelement) method, I am getting error as
Element belongs to a different frame than the current one
My sample webpage has 2 frames name as FrameOne and FrameTwo with one textbox in each frame.. in 1st frame as name 1 and textbox in 2nd frame as name 2.
driver.navigate().to("file:///D:/Study%20material/8850OS_Code/Chapter%203/HTML/Frames.html");
/***********By id***********************/
driver.switchTo().frame(1); //identify 2nd frame sucessfully
WebElement Textbox2=driver.findElement(By.name("2")); //webelement in 2nd frame
Textbox2.sendKeys("Hi Vivek");
driver.switchTo().defaultContent();
driver.switchTo().frame(0).findElement(By.name("1")).sendKeys("Hello selenium");
driver.switchTo().defaultContent();
/***
/***********By WebElement***********************/
driver.switchTo().frame(Textbox2); ---> this line throws error
Textbox2.sendKeys("Hi John");
driver.switchTo().defaultContent();
driver.switchTo().frame(0).findElement(By.name("1")).sendKeys("Hello selenium");
Please tell me how exactly this method works or where I am doing mistake.
You can not use textbox2 to switch to frame. The webelement overload for frame to locate iframe element like any other element.
WebElement iframe= driver.findElement(By.id(iframe));
driver.switchTo().frame(iframe);
Try this code. It worked for me...
driver.navigate().to("file:///D:/Study%20material/8850OS_Code/Chapter%203/HTML/Frames.html");
/***********By id***********************/
WebElement ifrm1= driver.findElement(By.id("FrameOne"));
WebElement ifrm2= driver.findElement(By.id("FrameTwo"));
driver.switchTo().frame(ifrm2); //identify 2nd frame sucessfully
WebElement Textbox2=driver.findElement(By.name("2")); //webelement in 2nd frame
Textbox2.sendKeys("Hi Vivek");
driver.switchTo().frame(ifrm1); // Switch Back to FrameOne
driver.findElement(By.name("1")).sendKeys("Hello selenium");
/***********By WebElement***********************/
driver.switchTo().frame(Textbox2);
The Above line throws error as "TextBox2" is not a Frame Element
More info on frames can be found at https://www.seleniumeasy.com/selenium-tutorials/how-to-work-with-iframes-in-selenium-webdriver
Hope its helpful

Save a data frame to a file addressing by name

I have a data frame and a text variable containing the name of this data frame:
adsl = data.frame(a=2, b=7, w=17)
ds_name = "adsl"
I want to save my data frame from the workspace to the file named "dest_file". The code should be wrapped into a function get_r()
with the data frame name as an argument:
get_r(ds_name="adsl")
So I need to avoid using the explicit name "adsl" inside the code.
The following works almost correctly but the resulting data frame is called "temp_dataset", not "adsl":
get_r = function(ds_name){
temp_dataset = eval(parse(text=ds_name))
save(temp_dataset, file = "dest_file")
}
Here is another option which works wrong (the text string is being saved, not the data frame):
get_r = function(ds_name){
save(ds_name, file = "dest_file")
}
What should I do to make R just execute
save(adsl, file="dest_file")
inside the function? Thank you for any help.
Try
save(list = ds_name, file = "dest_file")
The list argument in save() allows you to pass the name of the data as a character string. See help(save) for more.

converting properties in a list using EMF databinding does not convert values

I am trying to convert some values from integers to strings using a converter.
observerViewerValue = ViewerProperties.input().observe(tableViewer);
UpdateValueStrategy strategy = new UpdateValueStrategy();
strategy.setConverter(new ItemConverter());
IObservableValue observeItemValue = props[0].observe(peopleList);
bindingContext.bindValue(observerViewerValue, observeItemValue, strategy, strategy);
tableViewer.setInput(peopleList);
it doesn't like the fact that it has been given a list, I tried iterating through and doing:
IObservableValue observeItemValue = props[0].observe(peopleList.get(i));
where i is the index, no exceptions are thrown but the values aren't converted. props[0] just contains the property that will be watched.
I ended up overriding the ObservableMapLabelProvider and adding the converter in the getColumnText method, it did the trick...

Resources