作者rexyeah (ccccccc)
看板Python
标题Re: [问题] 用selenium爬虫instagram
时间Fri Feb 8 20:56:17 2019
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
(...)
def get_element(self, selector):
ele = WebDriverWait(self.driver, timeout).until(
EC.presence_of_element_located((By.CSS_SELECTOR, selector)))
return ele
===
以前爬的时候看stackoverflow写的一个等待element被画好然後回传element的method
timeout值可以自己设定,不过我没有处理exception,请原po与大家鞭一下 :)
※ 引述《ms0615122 (Miao~)》之铭言:
: 想请问爬instagram留言的时候
: 需要点选载入更多留言
: 我是使用find_element_by_xpath後.click()
: 因载入留言的时间长不一定
: 虽然有加入time.sleep()但有时还是会来不及载入,想请问有更智能的方法判断是否已经
: 载入好网页,我再用.click()吗?
: (曾经尝试过driver.implicitly_wait()过,但测试不出效果,可能这个函数只有在更换
: url才有效果?)
: 第一次在板上发问,请有经验的大大解答一下><,手机排版伤眼抱歉了
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.161.245.119
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1549630579.A.B9D.html
1F:推 Sunal: 只有我觉得selenium的各种方法很不直觉吗?XD 02/08 22:01
2F:推 utap2001: 这个wait的方法是还蛮不直觉的,好麻烦( ̄~ ̄) 02/08 22:36
3F:→ TitanEric: 这感觉有点async 02/08 23:40