The World’s Largest Online Community for Developers

'; selenium - how would i create these lines of python code into 1 variable? - LavOzs.Com

I am a beginner in python, I was wondering if i could put multiple lines of code into a variable by using the class and then execute the 2nd part of the code where it scrapes the website.

I still need to modify the website to obtain the gene name and (div,"class":"result result-gene tip-simple star") into the excel. I don't think i will have problem modifying the second part. but I was wondering how the first part of the code could be made into a variable where the second part scrapes that data variable data. so that the program would work on any cdi. inputing Y54E10A.9b would come out as

vbh-1 :Is an ortholog of human DDX3X (DEAD-box helicase 3 X-linked) and DDX3Y (DEAD-box helicase 3 Y-linked). Is predicted to have RNA binding activity and RNA helicase activity. Is involved in several processes, including masculinization of hermaphroditic germ-line; positive regulation of embryonic development; and positive regulation of fertilization. Localizes to P granule and cytoplasmic stress granule. Is expressed in several structures, including Z2; Z3; germ cell; somatic cell; and in male. Human ortholog(s) of this gene are implicated in Y-linked spermatogenic failure 2.

as a product

from selenium import webdriver
from import Options
from selenium.webdriver import Chrome
import pandas as pd
import time
from selenium.webdriver.common.keys import Keys
import pandas as pd

open_page = {

cdi = "R04B5.4a"

driver = webdriver.Chrome(r"C:\Users\hogyu\PycharmProjects\Project_Selenium\drivers\chromedriver.exe")

elem = driver.find_element_by_id("Search")
time.sleep(2) }


def getdata(start_url):
    urls = driver.get(start_url)
    df=pd.DataFrame(columns=['Gene_id',  'Description'])
    dictionary = {'One':1 , 'Two':2 }
    books = driver.find_elements_by_css_selector('div.results')
    for book in books:
        for b in book.find_elements_by_css_selector('div.result result-gene  tip-simple star'):
            data['Gene_id'] = b.find_elements_by_css_selector(' load-star')
            data['Description'] = b.find_elements_by_css_selector('div.text-min')[0].text
            df=df.append(data, ignore_index=True)
        df.index += 1 #Increments the index from 0 to 1
    return df

getdata(url).to_excel(r"C:/Users/hogyu/OneDrive/Desktop/Python codes/experiments/Wormbase.xlsx")

I assume that you want to continue roll down in the first part and get something as an input in the second part.

I will recomend you insert the second part into the first one and keep repeating.

Or if the first function is been used frequently, make it into a decorator!

def part_1(func, args, kwargs, driver...):
   # get part 1 web element
   t_obj = ...
       kwargs['search'] = t_obj # set it as obj input into func < part 2
       func(*args, **kwargs) # part 2
       # keep scrolling
       if ...:

Hope this will help you!