当前位置: 首页>>代码示例>>Python>>正文


Python Browser.is_element_present_by_value方法代码示例

本文整理汇总了Python中splinter.Browser.is_element_present_by_value方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.is_element_present_by_value方法的具体用法?Python Browser.is_element_present_by_value怎么用?Python Browser.is_element_present_by_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在splinter.Browser的用法示例。


在下文中一共展示了Browser.is_element_present_by_value方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_value [as 别名]
def main(argv):
    
    if len(argv)==0:
	help()

    report=hvf=hvw=tuits=False

    try:
        opts, args = getopt.getopt(argv,"hi:u:i:f:w:t:r",["file=","user=","followers=","following=", "tuits=","report="])
    except getopt.GetoptError:
	help()

    for opt, arg in opts:

	if opt == '-h':
	    help()
	elif opt in ("-i", "--file"):
	    txt = arg
	elif opt in ("-u", "--user"):
	    username = arg
	elif opt in ("-f", "--followers") and arg=="y":
	    hvf=True
	elif opt in ("-w", "--following") and arg=="y":
	    hvw=True
	elif opt in ("-t", "--tuits") and arg=="y":
	    tuits=True
	elif opt in ("-r", "--report") and arg=="y":
	    report=True

    try:
	ufile = open(txt, 'rb').readlines()
    except:
	print "Cant open %s" % txt
	sys.exit(0)

    password = raw_input("Enter your twitter password : ")

    browser = Browser( 'firefox' , profile_preferences=proxy_settings )
    browser.visit("https://twitter.com/login/")
	
    if browser.is_element_present_by_value("Log in", wait_time=8):
	aloginb=browser.find_by_xpath('.//button[@type="submit"]')[0]
	logintw(browser, aloginb, username, password)		   
    else:
	print "timeout loading page"
	sys.exit(5)

    for line in ufile:

	try:
	    if re.search("intent", line):	
	        url = re.match(r"https?://(www\.)?twitter\.com/intent/(#!/)[email protected]?([^/\s]*)",line.strip())
	        url = url.group()
		urltypeid=True
	    else:	
	        url = line.strip()
		urltypeid=False	
	    browser.visit(url)
	    time.sleep(1)	
	    if not re.search('suspended', browser.url):
		if urltypeid:
	            browser.find_by_css('a.fn.url.alternate-context').click()
	    else:
		msg =  line.strip() + ' - Suspended'
		logger(msg)
		continue

	    # report user
			
	    msg="  "
			
	    if report:	
	        report(browser)
		msg="RP"

	    id = browser.find_by_css('a.ProfileHeaderCard-screennameLink.u-linkComplex.js-nav')["href"][1:]
	    id = id.split("/")[-1]
	    followers = browser.find_by_css('a[data-nav="followers"] .ProfileNav-value')
	    following = browser.find_by_css('a[data-nav="following"] .ProfileNav-value')	

	    try:
		msg = "%s %s %s %s" % (followers.value, following.value, url.strip(), msg)
	    except:
		msg = " %s %s " % (url.strip(), msg) 	

	    # harvest twitters

	    if tuits:	
		if goGetTwitters(id, browser):
		    msg+=" TW"

	    # harvest followers

	    if hvf:
		if goharvest(id, browser, "followers"):
		    msg+=" FO"
	
	    # harvest following
				
	    if hvw:
#.........这里部分代码省略.........
开发者ID:lelou6666,项目名称:opparis,代码行数:103,代码来源:tr6.py


注:本文中的splinter.Browser.is_element_present_by_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。