遍历页面 |硒 | ElementNotInteractableException:消息:元素不可交互
Iterate over pages | selenium | ElementNotInteractableException: Message: element not interactable
请查看附件截图。
页面由 1 条推文 table 中的 20 条推文组成。每条推文每页分别有 20 条推文 table 2,3,4,5。我能够获取 1 条推文 table,即前 20 条推文。但是如何获取所有 5 条推文-table?因为 2 不是屏幕截图中突出显示的 button。
我尝试使用完整的 xpath 但是它给了
second_button = driver.find_element_by_xpath(
'/html/body/div[1]/div[1]/div[1]/div[5]/div/div/div/div[3]/div[2]/div/ul/li[3]').click()
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
首页代码,即 20 条推文:
driver.get("https://www.trackmyhashtag.com/")
form = driver.find_element_by_xpath("//*[@class='container']")
usrinput = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[1]/input')
usrinput.clear()
usrinput.send_keys("india")
loginbt = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[2]/button')
loginbt.click()
time.sleep(5)
ad = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button')
ad.click()
time.sleep(5)
element = driver.find_element_by_xpath('/html/body/aside/nav/div/ul/li[2]/a')
actions = ActionChains(driver)
actions.move_to_element(element).perform()
actions.click().perform()
time.sleep(5)
ad=wait.until(driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button'))
actions = ActionChains(driver)
rows = driver.find_elements_by_xpath("//tr[@role='row' and(@class)]")
for i in range(1,len(rows)+1):
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
actions.move_to_element(row).perform()
time.sleep(1)
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
name = row.find_element_by_xpath(".//div[@class='tweet-name']").text
content = row.find_element_by_xpath(".//td[2]").text
date = row.find_element_by_xpath(".//td[2]").text
impressions = row.find_element_by_xpath(".//td[6]").text
从第 1 页抓取所有 20 条推文后,您需要向下滚动到最后,然后单击第 2 页,并对所有页面重复相同的过程。
完整代码:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
options = webdriver.ChromeOptions()
options.add_argument("--disable-infobars")
options.add_argument("--disable-notifications")
options.add_argument("--start-maximized")
options.add_argument("--disable-extensions")
options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 2})
options.add_argument('--window-size=1920,1080')
options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
driver = webdriver.Chrome(executable_path = driver_path, options = options)
#driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(50)
driver.get("https://www.trackmyhashtag.com/")
wait = WebDriverWait(driver, 10)
actions = ActionChains(driver)
wait.until(EC.visibility_of_element_located((By.ID, "search_keyword"))).send_keys("India", Keys.RETURN)
def close_up():
time.sleep(1)
actions.move_to_element(wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@data-dismiss='modal']"))))
button = driver.find_element_by_xpath("//button[@data-dismiss='modal']")
driver.execute_script("arguments[0].click();", button)
time.sleep(1)
def check_model_winodows():
try:
if len(driver.find_elements(By.XPATH, "(//button[@data-dismiss='modal'])[1]")) >0:
print("Pop up is visible")
close_up()
else:
print("Pop up is not visible")
except:
print("Something went wrong")
pass
check_model_winodows()
button = driver.find_element_by_css_selector("a[onclick*='preview-tweets']")
driver.execute_script("arguments[0].click();", button)
#wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ""))).click()
check_model_winodows()
total_number_of_tweet_row = len(driver.find_elements(By.XPATH, "//tbody/tr"))
print(total_number_of_tweet_row)
page_number = 2
total_number_of_pages = 5
for a in range(total_number_of_pages):
j = 0
for i in range(total_number_of_tweet_row):
check_model_winodows()
elems = driver.find_elements(By.XPATH, "//tbody/tr")
time.sleep(1)
final_ele = elems[j].find_element_by_xpath(".//td[2]")
print("code worked till here")
print(final_ele.text)
j = j + 1
check_model_winodows()
driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
wait.until(EC.element_to_be_clickable((By.XPATH, f"//a[text()='{page_number}']"))).click()
page_number = page_number + 1
if page_number == 5:
break
输出:
"C:\Program Files\Python39\python.exe" C:/Users/panabh02/PycharmProjects/SeleniumSO/Chrome.py
Pop up is visible
Pop up is visible
20
Pop up is visible
code worked till here
RT @TarekFatah: Here comes the threat to India by the Pakistani Taliban. “We will fly the Pakistan flag over Delhi in less than 24 hours,...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@cz_binance @Btcexpertindia @binance @cz_binance you are popular in South India also
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules usher in a landmark moment for this sector in India. The rules are based on the premise of trust and?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @priya_malviy24: #रेल_ग्रुपD_परीक्षा_कराओ It is our new India/digital India where election campaign...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sardesairajdeep: Part of the golden 50s generation when English cricketers came through the Oxbridge system. No one I am told straight?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @SuryawaSingh: @NaveenK81494169 ना तख्त चाहिए , ना ताज चाहिए , हमें तो बस ops ?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @harshasherni: Mesmerizing view Somewhere near Vattavada a village in Idukki district in the state of Kerala, India. @KeralaTourism ht...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @vivekagnihotri: 100% lobbying for vegan brands, almond milk etc. They just want @Amul_Coop to shut down. India is the largest milk prod?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @arslansaduzai: 64/n A woman is attacked, passing by men watch motionlessly. The incident took place on #InternationalWomensDay in Delhi?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Chhotalikharii: India's farmer protest 273 days, 601 deaths #9MonthsOfFarmersProtes
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@BSNL_HR @airtelindia @MCManesar @DoT_India Village Baskushla doesn't have any broadband service, ppl struggling to do WFH, students struggl...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @DennisCricket_: India have announced that Abhinandan will bat at 3 in the next Test. "Not even he crashes as bad as what we just saw?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
#JammuAndKashmir | Attack on press freedom': J&K HC quashes FIR against journalist for reporting police torture. @naseerganai @JmuKmrPo...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@FOBDoda @sikander_Quresh The freedom struggle is incomplete without talking about the famous Quit India Movement & its phases. In th...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ErikSolheim: Incredible India ! Reverse waterfall in Naneghat, Maharashtra .
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Sharanyashettyy: Very instructive. Chinese nationals are now giving up their citizenship to hide their allegiance. As a country we need?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules usher in a landmark moment for this sector in India. The rules are based on the premise of trust and?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @CPhhp: #Run4India #AzadiKaMahotsav 103 cdts of 1 Pb Bn NCC of Amritsar Gp participated in the Fit India Freedom Run org by Distt Admi?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sanjeevaiacewa: #SamePayForSameWork #PayRevisionFrom2017 Sir we NACP EMPLOYEES working in very low pay are requesting you to please RE?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @NamdevVaishu: HAPPY BIRTHDAY RUBINA has started Trending last Night and still has its place in india Trend list Another proof of organi?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules usher in a landmark moment for this sector in India. The rules are based on the premise of trust and?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
Ghosts make for a busy night aboard the Star of India paranormal #Radio
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @IMinakshiJoshi: #India में #Corona के मामले बढ़े. पिछले 24 घंटे में 46 हजार ...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @theskindoctor13: @ANI TaIiban didn't kiII him, hate did. Same hate that in India RSS harbours for minorities. Hence proved RSS is respo?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @idnani_nandini: Sad moment 140 Sikh Brothers denied Pilgrimage in India All held up by Taliban didn't allowed them to reach #Kabulair?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ndtvindia: पुलिस अफसरों के सत्ताधारी दलों के साथ गठजोड़ पर...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @BiotechClinical: @MSWA123 @AmitV_Deshmukh @of_interns @vikalp_ek @AyurvedaStuden1 @Ayurtalk45 @AiAyushMedUnity @UnionAyush @BpmtSc @war?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @FXMC1957: 26 August 1910. Mother Teresa (Agnesë Bojaxhiu) was born in what is now Skopje, North Macedonia. She engaged in charitable ef...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @MinNara1227: #8MBrightsHug Trending 1 Worldwide 1 Thailand 1 Malaysia 1 Indonesia 1 Taiwan ...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
1989 batch IPS and Dg vigilance PV ramashastri appointed as New ADG @BSF_India. @ips_up @Uppolice @gyanu999 @Live_Gyan
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @itzzOriana: • Sachin vaze who's suspended for 17Years, but was granted bail & later reinstated in June2020. • On 6th June, MGov...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules will tremendously help start-ups and our youth working in this sector. It will open up new possibilit?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @latestly: Man Dodges Security Officials at Mumbai Airport, Flies to Bareilly on Friend's Ticket; Arrested #Mumbai #Bareilly #MumbaiAirp?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Atheist_Krishna: At present who is the worst Chief Minister in India?
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@realSonuNigam0 Agree @RahulGandhi @SoniaGhandhiIND Declare India a Hindu Rashtra
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ErikSolheim: Solar roof top is taking off in India ! Gujarat is leading the charge in installed capacity. @zubinashara https://...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @RedmiIndia: Prepare for finer things in life cause, it will be our FIRST TIME EVER in India with Qualcomm® Chipset! Ready for the "...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @PramodK88791564: @YouTubeIndia Gyan Gaming youtube channel got hacked ! What happens this youtube india @_GyanSujan_ @gamer_2b
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @IndiaTales7: One of the highest waterfalls in India- Witness the Majesty of Nature. #DekhoApnaDesh #IncredibleIndia https://t...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @RonaldLampard8: Indonesia berada di bawah China, India, Amerika Serikat, Brasil, dan Jepang. Per Rabu (25/8) sebanyak 59 juta orang tel?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @yasasreevinnu: The question that haunt me every time Why Salman not concentrated on south India #Salmanakhan #33YearsOfSalmanKhanEra
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: My valued colleague, Shri @alphonstourism has made a commendable effort to encapsulate facets of India’s reform journey ...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sparrow_grl_: कोरोना की लग चुकी है वैक्सीन, फिर क्यों कॉलेज ख?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @KrantiKKumar: खुशखबरी !!! All India Quota Medical Seats में 10% EWS आरक्षण लागू नही हो...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Me_For_Photon: Only Disha Salian case will open the lock of Sushant's case. Both the murders are connected. - SSR DISHA MURDER LINKE?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@mifz4L Ni north india do mmg keling kasta biol
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Pradeep19951213: @AshwiniVaishnaw @UmangOfficial_ @_DigitalIndia @GoI_MeitY @PMOIndia @PIB_India #रेल_ग्रुपD_परी?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ZpopF: Hlo GalaxZ, So I have been posting z stars quiz on my Instagram Stories you can join if you like to Link ?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @h59851687: From 'मैं देश नहीं बिकने दूंगा' to 'मैं सब कुछ बेच दूंग...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Omkar_Raii: .@GoI_MeitY planning to support 300 tech startups by providing seed funding, mentorship & market access and create 100 u...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @TrendsOfSTR: Our king #SilambarasanTR Tag on Trending in India level Time to Lead .. #Maanaadu #VendhuThanindhath...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @MeghUpdates: India can be a trillion market by 2025: Walmart
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @arslansaduzai: 37/n A woman resident of Ranwas village #India under Para police post in #Jhabua, #MadhyaPradesh, was forced to carry he?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @VinayKu86268222: @SarjuRamSahu1 @Jayendr10987039 @NaveenK81494169 @DRMSSY #NPSनिजीकरणभारतछोड़ो #NPSन?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sanjeevaiacewa: #SamePayForSameWork #PayRevisionFrom2017 Sir we NACP EMPLOYEES working in very low pay are requesting you to please RE?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @jorloplaz: Y las variantes: A) “La variante india hace estragos y hay que vacunar a todos”. Pero: B) En La India esa variante ha d...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @nitinagarwalINC: From 'मैं देश नहीं बिकने दूंगा' to 'मैं सब कुछ बेच दू...
Pop up is visible
Something went wrong
Pop up is visible
您可以从首页推文中获取数据。然后检查是否启用了下一页按钮。如果是这样 - 向上滚动页面然后单击下一页按钮并获取新数据并再次检查下一页按钮。如果启用 - 单击它,否则 - 停止循环。
driver.get("https://www.trackmyhashtag.com/")
form = driver.find_element_by_xpath("//*[@class='container']")
usrinput = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[1]/input')
usrinput.clear()
usrinput.send_keys("india")
loginbt = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[2]/button')
loginbt.click()
time.sleep(5)
ad = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button')
ad.click()
time.sleep(5)
element = driver.find_element_by_xpath('/html/body/aside/nav/div/ul/li[2]/a')
actions = ActionChains(driver)
actions.move_to_element(element).perform()
actions.click().perform()
time.sleep(5)
ad=wait.until(driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button'))
actions = ActionChains(driver)
next_page_link_css = 'li.paginate_button.page-item.next a'
next_page_css = 'li.paginate_button.page-item.next'
while True:
rows = driver.find_elements_by_xpath("//tr[@role='row' and(@class)]")
for i in range(1,len(rows)+1):
time.sleep(1)
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
actions.move_to_element(row).perform()
time.sleep(1)
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
name = row.find_element_by_xpath(".//div[@class='tweet-name']").text
content = row.find_element_by_xpath(".//td[2]").text
date = row.find_element_by_xpath(".//td[2]").text
impressions = row.find_element_by_xpath(".//td[6]").text
next_page_class = driver.find_element_by_css(next_page_css).get_attribute("class")
if not 'disabled' in next_page_class:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
next_page_link_btn = driver.find_element_by_css_selector(next_page_link_css)
driver.execute_script("arguments[0].click();", next_page_link_btn)
time.sleep(2)
else:
break
请查看附件截图。 页面由 1 条推文 table 中的 20 条推文组成。每条推文每页分别有 20 条推文 table 2,3,4,5。我能够获取 1 条推文 table,即前 20 条推文。但是如何获取所有 5 条推文-table?因为 2 不是屏幕截图中突出显示的 button。
我尝试使用完整的 xpath 但是它给了
second_button = driver.find_element_by_xpath(
'/html/body/div[1]/div[1]/div[1]/div[5]/div/div/div/div[3]/div[2]/div/ul/li[3]').click()
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
首页代码,即 20 条推文:
driver.get("https://www.trackmyhashtag.com/")
form = driver.find_element_by_xpath("//*[@class='container']")
usrinput = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[1]/input')
usrinput.clear()
usrinput.send_keys("india")
loginbt = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[2]/button')
loginbt.click()
time.sleep(5)
ad = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button')
ad.click()
time.sleep(5)
element = driver.find_element_by_xpath('/html/body/aside/nav/div/ul/li[2]/a')
actions = ActionChains(driver)
actions.move_to_element(element).perform()
actions.click().perform()
time.sleep(5)
ad=wait.until(driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button'))
actions = ActionChains(driver)
rows = driver.find_elements_by_xpath("//tr[@role='row' and(@class)]")
for i in range(1,len(rows)+1):
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
actions.move_to_element(row).perform()
time.sleep(1)
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
name = row.find_element_by_xpath(".//div[@class='tweet-name']").text
content = row.find_element_by_xpath(".//td[2]").text
date = row.find_element_by_xpath(".//td[2]").text
impressions = row.find_element_by_xpath(".//td[6]").text
从第 1 页抓取所有 20 条推文后,您需要向下滚动到最后,然后单击第 2 页,并对所有页面重复相同的过程。
完整代码:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
options = webdriver.ChromeOptions()
options.add_argument("--disable-infobars")
options.add_argument("--disable-notifications")
options.add_argument("--start-maximized")
options.add_argument("--disable-extensions")
options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 2})
options.add_argument('--window-size=1920,1080')
options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
driver = webdriver.Chrome(executable_path = driver_path, options = options)
#driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(50)
driver.get("https://www.trackmyhashtag.com/")
wait = WebDriverWait(driver, 10)
actions = ActionChains(driver)
wait.until(EC.visibility_of_element_located((By.ID, "search_keyword"))).send_keys("India", Keys.RETURN)
def close_up():
time.sleep(1)
actions.move_to_element(wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@data-dismiss='modal']"))))
button = driver.find_element_by_xpath("//button[@data-dismiss='modal']")
driver.execute_script("arguments[0].click();", button)
time.sleep(1)
def check_model_winodows():
try:
if len(driver.find_elements(By.XPATH, "(//button[@data-dismiss='modal'])[1]")) >0:
print("Pop up is visible")
close_up()
else:
print("Pop up is not visible")
except:
print("Something went wrong")
pass
check_model_winodows()
button = driver.find_element_by_css_selector("a[onclick*='preview-tweets']")
driver.execute_script("arguments[0].click();", button)
#wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ""))).click()
check_model_winodows()
total_number_of_tweet_row = len(driver.find_elements(By.XPATH, "//tbody/tr"))
print(total_number_of_tweet_row)
page_number = 2
total_number_of_pages = 5
for a in range(total_number_of_pages):
j = 0
for i in range(total_number_of_tweet_row):
check_model_winodows()
elems = driver.find_elements(By.XPATH, "//tbody/tr")
time.sleep(1)
final_ele = elems[j].find_element_by_xpath(".//td[2]")
print("code worked till here")
print(final_ele.text)
j = j + 1
check_model_winodows()
driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
wait.until(EC.element_to_be_clickable((By.XPATH, f"//a[text()='{page_number}']"))).click()
page_number = page_number + 1
if page_number == 5:
break
输出:
"C:\Program Files\Python39\python.exe" C:/Users/panabh02/PycharmProjects/SeleniumSO/Chrome.py
Pop up is visible
Pop up is visible
20
Pop up is visible
code worked till here
RT @TarekFatah: Here comes the threat to India by the Pakistani Taliban. “We will fly the Pakistan flag over Delhi in less than 24 hours,...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@cz_binance @Btcexpertindia @binance @cz_binance you are popular in South India also
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules usher in a landmark moment for this sector in India. The rules are based on the premise of trust and?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @priya_malviy24: #रेल_ग्रुपD_परीक्षा_कराओ It is our new India/digital India where election campaign...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sardesairajdeep: Part of the golden 50s generation when English cricketers came through the Oxbridge system. No one I am told straight?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @SuryawaSingh: @NaveenK81494169 ना तख्त चाहिए , ना ताज चाहिए , हमें तो बस ops ?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @harshasherni: Mesmerizing view Somewhere near Vattavada a village in Idukki district in the state of Kerala, India. @KeralaTourism ht...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @vivekagnihotri: 100% lobbying for vegan brands, almond milk etc. They just want @Amul_Coop to shut down. India is the largest milk prod?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @arslansaduzai: 64/n A woman is attacked, passing by men watch motionlessly. The incident took place on #InternationalWomensDay in Delhi?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Chhotalikharii: India's farmer protest 273 days, 601 deaths #9MonthsOfFarmersProtes
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@BSNL_HR @airtelindia @MCManesar @DoT_India Village Baskushla doesn't have any broadband service, ppl struggling to do WFH, students struggl...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @DennisCricket_: India have announced that Abhinandan will bat at 3 in the next Test. "Not even he crashes as bad as what we just saw?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
#JammuAndKashmir | Attack on press freedom': J&K HC quashes FIR against journalist for reporting police torture. @naseerganai @JmuKmrPo...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@FOBDoda @sikander_Quresh The freedom struggle is incomplete without talking about the famous Quit India Movement & its phases. In th...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ErikSolheim: Incredible India ! Reverse waterfall in Naneghat, Maharashtra .
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Sharanyashettyy: Very instructive. Chinese nationals are now giving up their citizenship to hide their allegiance. As a country we need?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules usher in a landmark moment for this sector in India. The rules are based on the premise of trust and?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @CPhhp: #Run4India #AzadiKaMahotsav 103 cdts of 1 Pb Bn NCC of Amritsar Gp participated in the Fit India Freedom Run org by Distt Admi?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sanjeevaiacewa: #SamePayForSameWork #PayRevisionFrom2017 Sir we NACP EMPLOYEES working in very low pay are requesting you to please RE?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @NamdevVaishu: HAPPY BIRTHDAY RUBINA has started Trending last Night and still has its place in india Trend list Another proof of organi?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules usher in a landmark moment for this sector in India. The rules are based on the premise of trust and?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
Ghosts make for a busy night aboard the Star of India paranormal #Radio
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @IMinakshiJoshi: #India में #Corona के मामले बढ़े. पिछले 24 घंटे में 46 हजार ...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @theskindoctor13: @ANI TaIiban didn't kiII him, hate did. Same hate that in India RSS harbours for minorities. Hence proved RSS is respo?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @idnani_nandini: Sad moment 140 Sikh Brothers denied Pilgrimage in India All held up by Taliban didn't allowed them to reach #Kabulair?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ndtvindia: पुलिस अफसरों के सत्ताधारी दलों के साथ गठजोड़ पर...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @BiotechClinical: @MSWA123 @AmitV_Deshmukh @of_interns @vikalp_ek @AyurvedaStuden1 @Ayurtalk45 @AiAyushMedUnity @UnionAyush @BpmtSc @war?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @FXMC1957: 26 August 1910. Mother Teresa (Agnesë Bojaxhiu) was born in what is now Skopje, North Macedonia. She engaged in charitable ef...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @MinNara1227: #8MBrightsHug Trending 1 Worldwide 1 Thailand 1 Malaysia 1 Indonesia 1 Taiwan ...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
1989 batch IPS and Dg vigilance PV ramashastri appointed as New ADG @BSF_India. @ips_up @Uppolice @gyanu999 @Live_Gyan
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @itzzOriana: • Sachin vaze who's suspended for 17Years, but was granted bail & later reinstated in June2020. • On 6th June, MGov...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: The new Drone Rules will tremendously help start-ups and our youth working in this sector. It will open up new possibilit?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @latestly: Man Dodges Security Officials at Mumbai Airport, Flies to Bareilly on Friend's Ticket; Arrested #Mumbai #Bareilly #MumbaiAirp?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Atheist_Krishna: At present who is the worst Chief Minister in India?
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@realSonuNigam0 Agree @RahulGandhi @SoniaGhandhiIND Declare India a Hindu Rashtra
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ErikSolheim: Solar roof top is taking off in India ! Gujarat is leading the charge in installed capacity. @zubinashara https://...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @RedmiIndia: Prepare for finer things in life cause, it will be our FIRST TIME EVER in India with Qualcomm® Chipset! Ready for the "...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @PramodK88791564: @YouTubeIndia Gyan Gaming youtube channel got hacked ! What happens this youtube india @_GyanSujan_ @gamer_2b
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @IndiaTales7: One of the highest waterfalls in India- Witness the Majesty of Nature. #DekhoApnaDesh #IncredibleIndia https://t...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @RonaldLampard8: Indonesia berada di bawah China, India, Amerika Serikat, Brasil, dan Jepang. Per Rabu (25/8) sebanyak 59 juta orang tel?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @yasasreevinnu: The question that haunt me every time Why Salman not concentrated on south India #Salmanakhan #33YearsOfSalmanKhanEra
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @narendramodi: My valued colleague, Shri @alphonstourism has made a commendable effort to encapsulate facets of India’s reform journey ...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sparrow_grl_: कोरोना की लग चुकी है वैक्सीन, फिर क्यों कॉलेज ख?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @KrantiKKumar: खुशखबरी !!! All India Quota Medical Seats में 10% EWS आरक्षण लागू नही हो...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Me_For_Photon: Only Disha Salian case will open the lock of Sushant's case. Both the murders are connected. - SSR DISHA MURDER LINKE?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
@mifz4L Ni north india do mmg keling kasta biol
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Pradeep19951213: @AshwiniVaishnaw @UmangOfficial_ @_DigitalIndia @GoI_MeitY @PMOIndia @PIB_India #रेल_ग्रुपD_परी?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @ZpopF: Hlo GalaxZ, So I have been posting z stars quiz on my Instagram Stories you can join if you like to Link ?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @h59851687: From 'मैं देश नहीं बिकने दूंगा' to 'मैं सब कुछ बेच दूंग...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @Omkar_Raii: .@GoI_MeitY planning to support 300 tech startups by providing seed funding, mentorship & market access and create 100 u...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @TrendsOfSTR: Our king #SilambarasanTR Tag on Trending in India level Time to Lead .. #Maanaadu #VendhuThanindhath...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @MeghUpdates: India can be a trillion market by 2025: Walmart
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @arslansaduzai: 37/n A woman resident of Ranwas village #India under Para police post in #Jhabua, #MadhyaPradesh, was forced to carry he?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @VinayKu86268222: @SarjuRamSahu1 @Jayendr10987039 @NaveenK81494169 @DRMSSY #NPSनिजीकरणभारतछोड़ो #NPSन?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @sanjeevaiacewa: #SamePayForSameWork #PayRevisionFrom2017 Sir we NACP EMPLOYEES working in very low pay are requesting you to please RE?...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @jorloplaz: Y las variantes: A) “La variante india hace estragos y hay que vacunar a todos”. Pero: B) En La India esa variante ha d...
Pop up is visible
Something went wrong
Pop up is visible
Something went wrong
code worked till here
RT @nitinagarwalINC: From 'मैं देश नहीं बिकने दूंगा' to 'मैं सब कुछ बेच दू...
Pop up is visible
Something went wrong
Pop up is visible
您可以从首页推文中获取数据。然后检查是否启用了下一页按钮。如果是这样 - 向上滚动页面然后单击下一页按钮并获取新数据并再次检查下一页按钮。如果启用 - 单击它,否则 - 停止循环。
driver.get("https://www.trackmyhashtag.com/")
form = driver.find_element_by_xpath("//*[@class='container']")
usrinput = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[1]/input')
usrinput.clear()
usrinput.send_keys("india")
loginbt = driver.find_element_by_xpath('/html/body/header/div[2]/div/div[2]/form/div/div[2]/button')
loginbt.click()
time.sleep(5)
ad = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button')
ad.click()
time.sleep(5)
element = driver.find_element_by_xpath('/html/body/aside/nav/div/ul/li[2]/a')
actions = ActionChains(driver)
actions.move_to_element(element).perform()
actions.click().perform()
time.sleep(5)
ad=wait.until(driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/div/div/div/button'))
actions = ActionChains(driver)
next_page_link_css = 'li.paginate_button.page-item.next a'
next_page_css = 'li.paginate_button.page-item.next'
while True:
rows = driver.find_elements_by_xpath("//tr[@role='row' and(@class)]")
for i in range(1,len(rows)+1):
time.sleep(1)
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
actions.move_to_element(row).perform()
time.sleep(1)
row = driver.find_element_by_xpath("(//tr[@role='row' and(@class)])[" + str(i) + "]")
name = row.find_element_by_xpath(".//div[@class='tweet-name']").text
content = row.find_element_by_xpath(".//td[2]").text
date = row.find_element_by_xpath(".//td[2]").text
impressions = row.find_element_by_xpath(".//td[6]").text
next_page_class = driver.find_element_by_css(next_page_css).get_attribute("class")
if not 'disabled' in next_page_class:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
next_page_link_btn = driver.find_element_by_css_selector(next_page_link_css)
driver.execute_script("arguments[0].click();", next_page_link_btn)
time.sleep(2)
else:
break