Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

python - Multiple selenium links one by one

I want it to open a new link from a text pad after every loop I got it to work but on my code I put it in and it is not working the code to do it was


lines = a_file.readlines()
for line in lines:

web = webdriver.Chrome()
web.get(line)

here it is in my code when i put it in

in_stock = '//*[@id="viewport"]/div[5]/div/div[2]/div[3]/div[1]/div/div[3]/div[1]/div[2]/button'
a_file = open("links.txt")

lines = a_file.readlines()
for line in lines:








    def webscraper():



                web = webdriver.Chrome()
                web.get(line)

                time.sleep(1)
                try:
                    links = web.find_elements_by_xpath('//meta[@property="og:image"]')
                    for post in links:
                        value1 = post.get_attribute("Content")

                    title = web.find_elements_by_xpath('//*[@id="viewport"]/div[5]/div/div[1]/div[2]/h1')
                    for post in title:
                        finale = (post.text)
                    price = web.find_elements_by_xpath('//*[@id="viewport"]/div[5]/div/div[2]/div[2]/div[1]/div[1]/div[1]')
                    for post in price:
                        cost = (post.text)


                    instock_button = web.find_element_by_xpath(in_stock).click()
                    james = (finale +"
 INSTOCK" + "   PRICE:  " + cost)
                    current_link = (web.current_url)
                except NoSuchElementException:
                    james = (finale +" 
 OOS" + "   PRICE:  " + cost)
                    current_link = (web.current_url)
                links = web.find_elements_by_xpath('//meta[@property="og:image"]')
                for post in links:
                    value1 = post.get_attribute("Content")
                web.quit()
                return ( james, current_link, value1 )




@bot.command()
async def startTarget(ctx):
    while True:
        result = await bot.loop.run_in_executor(None, webscraper)
        embed = discord.Embed(title = "PURCHASE",url = result[1] , color=0xbbff00)
        embed.set_author(name= "LINK")
        embed.set_thumbnail(
            url="https:"+result[2])
        embed.add_field(name="ITEM:","" value=result[0], inline=False)
        embed.set_footer(text="Provided by me"  )
        await ctx.send(embed=embed)

And when I run this and start the bot it only checks on link and keeps going over one link over and over

question from:https://stackoverflow.com/questions/65837886/multiple-selenium-links-one-by-one

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...