[英]Output to fetch in single row
例子:
Reporter = driver.find_element_by_xpath("/html/body/div[1]/section/div[1]/div[3]/div/div/div/div/div/div/div[2]/div/issuetable-web-component/table/tbody/tr[" + p + "]/td[5]/span/a").get_attribute('rel')
s = Reporter
Output:
user1
user2
预期的:
user1,user2
您可以尝试格式化 output:
your_string = """
user1
user2
"""
如果您需要它作为像您的评论一样的元组:
new_tuple = tuple(your_string.strip().splitlines())
或作为字符串:
",".join([str(x) for x in your_string.strip().splitlines()])
考虑到您的循环正在填充 Reporter,它是一个字符串列表
Reporter = driver.find_element_by_xpath("/html/body/div[1]/section/div[1]/div[3]/div/div/div/div/div/div/div[2]/div/issuetable-web-component/table/tbody/tr[" + p + "]/td[5]/span/a").get_attribute('rel')
// joins elements of Reporter by ',' and stores in sting s
s = ","
s = s.join(Reporter)
也许尝试以下并检查 -
s = s.replace('\n', ',')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.