Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do locate same tag and click the target tag? #57

Open
utmcontent opened this issue May 8, 2021 · 1 comment
Open

How do locate same tag and click the target tag? #57

utmcontent opened this issue May 8, 2021 · 1 comment

Comments

@utmcontent
Copy link

utmcontent commented May 8, 2021

Suppose I have a bunch of tags in the page:

from os import stat,listdir,getcwd,rename,walk,listdir,remove,mkdir
from re import compile,search,match
from os.path import splitext,exists
from datetime import datetime
from json import dump,load,loads
import sys,io
from random import randint
from time import sleep
import time
import re
from helium import *
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
import argparse
class DeleteSome(object): 
    def __init__(self):
        # write("Hello World!")
        start_chrome("www.baidu.com")
        #login
        click("登录")
        click("用户名登录")
        write("myusername", into="手机/邮箱/用户名")
        write("mypwd", into="密码")
        click("登录")
        sleep(10)
        #Suppose go to page like a "Chinese" reddit page
        go_to('https://tieba.baidu.com/p/7287171441?pn=1')
        url=Link("尾页").href
        print (url,dir(url))
        go_to(url)
        c=find_all(S("//li[@class='d_name']"))
        #filter wrong advertising tag
        c=[i for i in c if i.web_element.text.strip()!="逍遥加速器" and i.web_element.text.strip()!="51星变"]
        dddd=[i.web_element.text.strip() for i in c]
        print (dddd)
        #find
        d=find_all(S("//div[@class='core_reply_tail clearfix']"))
        eee=find_all(S("//span[@class='tail-info']"))
        eee=[j for i,j in enumerate(eee) if re.search("\d{1,}楼",j.web_element.text)]
        print(len(c),len(d),len(eee))#iterate tags must have same length and in same div tag
        #iterate
        for i,j,k in zip(c,d,eee):
            dname=i.web_element.get_attribute('data-field')
            string_flag=k.web_element.text
            if dname=='{"user_id":1258865446}':
                sleep(2)
                string_flag=k.web_element.text
                print ("find tag")
                print(string_flag)
                #find specfic tag and delete
                if Link("删除", to_left_of=string_flag).exists():
                    print("按钮存在")#can find but cannot click right tag
#This is the issue I cant click the right delete tag with to_left_of parameter,while I can use click("删除") delete the first tag how do I use to_left_of to_right_of tag ,Documentation is not very clear.
                    click(Link("删除",to_left_of=string_flag))

                    sleep(5)
                    click("确认")
                else:
                    print("按钮不存在")
        sleep(10)
        end=True
        if end:
            kill_browser()

if __name__=='__main__':
    f=[]
    parser = argparse.ArgumentParser(description='命令行中传入文件名')
    parser.add_argument("--fname",nargs="+",default=f,help="文件名")
    args = parser.parse_args()
    instance=DeleteSome()

How do I get tag inside tag attribute in iteration tag?
How do I click the certain same tag with other tag when locate the tag in forloop?

@utmcontent
Copy link
Author

click(Link("删除",to_left_of=string_flag))
click(Link("删除",to_left_of=string_flag))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant