selenium webdriver chrome taobao 구글 키워드
selenium webdriver chrome taobao
selenium webdriver chrome taobao
<!DOCTYPE html>
<html>
<head>
<!-- HTML meta refresh 301 permanent redirection -->
<meta http-equiv="refresh" content="0; url=https://korkang91.tistory.com”>
</head>
<body>
<p>새로운 주소:
강비씨의 블로그</a></p>
</body>
</html>
다음은 위의 순서대로 브라우저와 웹서버가 주고 받은 HTTP 메시지 예 입니다.
1번 요청
GET http://www.test.com/page1 HTTP/1.1
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: ko-KR
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: www.test.com
Connection: Keep-Alive
Pragma: no-cache
2번 웹서버로부터 응답
Location 값은 /page2 와 같이 서버측의 상대 경로일 수도 있습니다.
HTTP/1.1 302
Location: http://www.test.com/page2
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Tue, 13 Feb 2018 10:33:15 GMT
3번 리다이렉트 경로로 재 요청
GET http://www.test.com/page2 HTTP/1.1
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: ko-KR
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: www.test.com
Connection: Keep-Alive
Pragma: no-cache
출처: https://dololak.tistory.com/147 [코끼리를 냉장고에 넣는 방법]
# 等待滑动验证码出现,超时时间为5秒,每0.5秒检查一次<font></font>
# 大部分情况不会出现滑动验证码,所以如果有需要可以注释掉下面的代码<font></font>
# sleep(5)<font></font>
WebDriverWait(self.browser, 5, 0.5).until(EC.presence_of_element_located((By.ID, "nc_1_n1z"))) #等待滑动拖动控件出现<font></font>
try:<font></font>
swipe_button = self.browser.find_element_by_id('nc_1_n1z') #获取滑动拖动控件<font></font>
<font></font>
#模拟拽托<font></font>
action = ActionChains(self.browser) # 实例化一个action对象<font></font>
action.click_and_hold(swipe_button).perform() # perform()用来执行ActionChains中存储的行为<font></font>
action.reset_actions()<font></font>
action.move_by_offset(580, 0).perform() # 移动滑块<font></font>
<font></font>
except Exception as e:<font></font>
print ('get button failed: ', e)<font></font>
#https://blog.csdn.net/taojian_/article/details/97758632
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
import time
option = webdriver.ChromeOptions()
option.binary_location = r'E:\Chrome\Application\chrome.exe'
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# option.add_argument("--proxy-server=127.0.0.1:8080")
# 设置无头加载
# option.add_argument('--headless')
# 设置无图片模式
# prefs = {"profile.managed_default_content_settings.images": 2}
# option.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=option)
driver.maximize_window()
status = driver.get("https://login.taobao.com/member/login.jhtml")
print(status)
# pass
# 删除原来的cookie
driver.delete_all_cookies()
# cookie = "thw=cn; cna=yFJuFf/jBmkCAbRt3g+PNikw; v=0; t=ce6433b7d755f402b91d17670f77a2ef; sg=819; csg=d16db728; existShop=MTU2MTYwNzg5MQ%3D%3D; tracknick=%5Cu6843%5Cu6843520328; lgc=%5Cu6843%5Cu6843520328; dnk=%5Cu6843%5Cu6843520328; tg=0; mt=ci=9_1; uc1=cookie16=U%2BGCWk%2F74Mx5tgzv3dWpnhjPaQ%3D%3D&cookie21=VT5L2FSpdet1FS8C2gIFaQ%3D%3D&cookie15=UIHiLt3xD8xYTw%3D%3D&existShop=false&pas=0&cookie14=UoTaGduh3ZQTWQ%3D%3D&tag=8&lng=zh_CN; _nk_=%5Cu6843%5Cu6843520328; _tb_token_=3ab35ef7b6b31; isg=BNrad6CZU8E-BN6SQyYSGTTBK4A8o13CtG3R4uRTgm04V3qRzJuu9aClIyNLgtZ9; l=bBNeS67nv7dTPyOoBOCanurza77OSIRYYuPzaNbMi_5LE6T_Z8bOkYnakF96Vj5RsUYB4ATie6p9-etkZ"
# c = cookie.split(';')
# ck = {}
# for i in c:
# key = i.split('=')[0].strip()
# val = i.split('=')[1].strip()
# ck.setdefault(key, val)
# 携带cookie打开
# driver.add_cookie(ck)
# 设置显示等待
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.ID, 'J_Quick2Static')))
# 打开淘宝二维码
i = driver.find_element_by_id("J_Quick2Static")
i.click()
user = driver.find_element_by_id("TPL_username_1")
user.send_keys('用户名')
password = driver.find_element_by_id("TPL_password_1")
password.send_keys('密码')
# 设置显示等待
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.ID, 'nc_1_n1z')))
bb = driver.find_element_by_id("nc_1_n1z")
# ActionChains(driver).click_and_hold(bb).perform()
# for x in range(258):
# ActionChains(driver).drag_and_drop_by_offset(
# xoffset=x, yoffset=0).perform()
# time.sleep(0.02)
bar_element = driver.find_element_by_id('nc_1_n1z')
ActionChains(driver).drag_and_drop_by_offset(bar_element, 258, 0).perform()
time.sleep(0.5)
ActionChains(driver).release().perform()
# 点击提交按钮
butt = driver.find_element_by_id('J_SubmitStatic')
butt.click()
driver.get("https://www.taobao.com")
# 设置显示等待
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located(
(By.CLASS_NAME, 'search-combobox-input-wrap')))
search = driver.find_element_by_class_name('search-combobox-input')
search.send_keys("苏宁易购")
search_butt = driver.find_element_by_class_name('btn-search')
search_butt.click()
print(driver.page_source)
————————————————
版权声明:本文为CSDN博主「怕疼的猫」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/taojian_/article/details/97758632
options = webdriver.ChromeOptions() options.add_experimental_option("excludeSwitches", ["enable-automation"]) caps = options.to_capabilities() driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=caps)
Since large websites now detect selenium tools, if selenium is detected, it is determined to be a robot and access is denied. So the first step is to prevent being detected as a robot. How to prevent it from being detected? When using selenium for automation, typing windows.navigator.webdriver in consloe in the chrome browser will find the result is True, and the value is False when the browser is used normally. So we will block windows.navigator.webdriver.
Add in the code:
def __init__(self): url = 'https://login.taobao.com/member/login.jhtml' self.url = url options = webdriver.ChromeOptions() options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2}) # Do not load images to speed up access options.add_experimental_option('excludeSwitches', ['enable-automation']) # This step is very important, set to developer mode to prevent the use of Selenium by major websites. self.browser = webdriver.Chrome(executable_path=chromedriver_path, options=options) self.wait = WebDriverWait(self.browser, 10) #Timeout is 10s