import os,time,threading
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
print(driver.title)
assert "百度" in driver.title # 这是断言,如果有百度关键字就往下执行
selenium = driver.find_element_by_id("kw")#找到百度输入框的id选择器的元素名字
selenium.send_keys("python")#设置要百度的关键字如“python”
selenium.send_keys(Keys.RETURN) #发送请求
print(driver.page_source)#输出请求结果
#以下的是练习,自动忽略就好
"""
options = webdriver.ChromeOptions()
options.add_argument('user-agent="Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://wenku.baidu.com/view/aa31a84bcf84b9d528ea7a2c.html")
#page = driver.find_elements_by_xpath("//div[@class='page']")
#driver.execute_script('arguments[0].scrollIntoView();', page[-1]) #拖动到可见的元素去
#ele=driver.find_element_by_class_name("foldpagewg-text")
#driver.execute_script("arguments[0].scrollIntoView();",ele)#移动到元素element对象的“顶端”与当前窗口的“顶部”对齐
#driver.execute_script("scroll(0,2400)")#大概的拖动
#driver.execute_script("arguments[0].scrollIntoView(false);",ele)#移动到元素element对象的“底端”与当前窗口的“底部”对齐
#driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")#移动到页面最底部
nextpage = driver.find_element_by_class_name("foldpagewg-text")
nextpage.click()
nextpage2 = driver.find_element_by_xpath("//div[@class='pagerwg-button']")
nextpage2.click()
"""
"""
print("process (%s) start.."% os.getpid())
pid = os.fork()
if(pid == 0):
print('I am child process (%s) and my parent is %s'%(os.getpid(),os.getppid()))
else:
print('I (%s) just created a child process (%s)'%(os.getpid(),pid))
"""
# -*- coding: utf-8 -*-
'''
class Person:
def __init__(self):
pass
def getAge(self):
print(__name__)
p = Person()
p.getAge()
a=[1,2,4,2,4,5,6,5,7,8,9,0]
b={}
#b=b.fromkeys(a)
#print(b)
c=list(list(set(a)))
print(c)
'''