[Twitter]删除多余注释

This commit is contained in:
DELL 2026-01-20 16:35:35 +08:00
parent 399165404e
commit 0008e619d1

View File

@ -89,85 +89,6 @@ class TwitterSpider(scrapy.Spider):
login_users=login_users,
response=response
)
# driver = response.request.meta['driver']
# driver.maximize_window()
# # 1. 打开第一个标签页
# driver.get('https://x.com/i/flow/login')
# user_list = []
# for u in login_users:
# user_list.append(json.loads(u.decode()))
#
# login_user = random.choice(user_list)
# wait = WebDriverWait(driver, 15)
# # 2. 通过 JS 打开第二个标签页(新 Tab
# time.sleep(5)
# driver.execute_script("window.open('');")
# driver.execute_script("window.open('https://x.com/i/flow/login', '_blank');")
#
# # 3. 获取所有标签页句柄
# handles = driver.window_handles # [handle1, handle2]
#
# # 4. 切换到第二个标签页(可选)
# driver.switch_to.window(handles[1])
#
# logger.info(f"login as user {login_user['uid']}")
# # time.sleep(random.uniform(1.5, 3.0))
# # driver.find_element_by_xpath("//input").send_keys(login_user['uid'])
# # 等待并定位用户名输入框
# username_input = wait.until(
# EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[autocomplete="username"]'))
# )
#
# # 模拟真人逐字输入(带随机延迟)
# username = login_user['uid']
# for char in username:
# username_input.send_keys(char)
# time.sleep(random.uniform(0.05, 0.2)) # 每个字符间隔 50~200ms
#
# time.sleep(random.uniform(0.3, 0.8)) # 输入完后稍作停顿
#
# # 尝试点击 "Next" 按钮(主逻辑:带文本的按钮)
# try:
# next_button = wait.until(
# EC.element_to_be_clickable(
# (By.XPATH, "//button[.//span[contains(text(), 'Next') or contains(text(), '下一步')]]")
# )
# )
# body = driver.find_element(By.TAG_NAME, "body")
# ActionChains(driver).move_to_element_with_offset(body, 100, 100).perform()
# time.sleep(0.5)
# # 模拟鼠标移动到按钮并点击
# actions = ActionChains(driver)
# actions.move_to_element(next_button).pause(random.uniform(0.2, 0.6)).click().perform()
#
# except Exception as e:
# logger.info("主 Next 按钮未找到,尝试备用定位方式")
# try:
# # 备用:通过 role 定位第二个 button
# next_button = driver.find_element(By.XPATH, "//button[@role='button'][2]")
# actions = ActionChains(driver)
# actions.move_to_element(next_button).pause(random.uniform(0.2, 0.6)).click().perform()
# except Exception as e2:
# logger.error(f"两种方式均无法点击 Next 按钮: {e}, {e2}")
# raise
# time.sleep(random.uniform(1.5, 5.0)) # 等待页面加载
# try:
# logger.info("输入手机号验证...")
# driver.find_element_by_xpath("//input[@name='text']").send_keys("+8619962025641")
# # driver.find_element_by_xpath("//button[@data-testid='ocfEnterTextNextButton']").click()
# driver.find_element_by_xpath(driver.find_element_by_xpath("//button[.//span[text()='下一步']]")).click()
# time.sleep(random.uniform(1.5, 5.0)) # 等待页面加载
# except Exception:
# logger.info("无需输入手机号验证")
# driver.find_element_by_xpath("//input[@name='password']").send_keys(login_user['pwd'])
# driver.find_element_by_xpath("//button[@data-testid='LoginForm_Login_Button']").click()
# time.sleep(random.uniform(1.5, 5.0)) # 等待页面加载
# try:
# driver.find_element_by_xpath("//button[@data-testid='confirmationSheetConfirm']").click()
# time.sleep(random.uniform(1.5, 10.0)) # 等待页面加载
# except:
# time.sleep(5)
cookies = driver.get_cookies()
# 取cookie中的ct0为x-csrf-token取gt为x-guest-token
self.cookie_dict = {}
@ -190,10 +111,8 @@ class TwitterSpider(scrapy.Spider):
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'content-type': 'application/json',
'authorization': self.authorization,
# 'x-twitter-active-user': 'yes',
'Origin': 'https://twitter.com',
'Cookie': cookie_string,
# 'Connection': 'keep-alive',
'X-Csrf-Token': ct0
}
self.filter_key = self.settings['TWITTER_FILTER_KEY']