ในตอนนี้ผมสามารถเขียนโปรเเกรมให้อ่านกระทู้( topic ต่างๆ)ทั้งหมดในหน้าแรกได้เเล้ว ตอนนี้ผมอยากได้คำเเนะนำการเขียนโปรเเกรมในส่วนของการเปิดหน้าถัดไป เพื่อที่สามารถอ่านกระทุ้(topic)ในหน้าถัดไป
ตัวอย่างโค้ดที่ผมลองเขียน
โค้ด: เลือกทั้งหมด
# -*- coding: utf-8 -*-
from selenium import webdriver #อิมพอร์ตโมดูล
import time
driver = webdriver.Firefox()
driver.get("https://www.mindphp.com/forums/viewforum.php?f=338")
time.sleep(2)
xpath_topic = " //a[@class='topictitle'] "
all_ids_topic = driver.find_elements_by_xpath(xpath_topic)
save_link = {}
no = 1
for a in driver.find_elements_by_xpath("//div[@class='pagination']/ul/li"): # element จำนวนหน้า
print(a)
for i in all_ids_topic: #ลูปการเก็บลิงค์และtopic
save_link[no] = i.get_attribute('href') +' , '+i.text
#print(no)
#print(i.text)
if no == 26: #เมื่อเปิดกระทู้(topic)หน้าเเรกหมด ให้ไปหน้าถัดไป
driver.find_elements_by_xpath("//li[@class='arrow next']/a[@class='button button-icon-only']")[0].click() #element ปุ่มของหน้าถัดไป
no=0
no+=1
for n, m in save_link.items(): # ลูปการเปิดลิ้ง
print(n)
print(m)
driver.get(m)
# driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
โค้ด: เลือกทั้งหมด
/home/com003/PycharmProjects/pythonProject_selenium_test/venv/bin/python /home/com003/PycharmProjects/pythonProject_selenium_test/venv/selenium_openwebtest01.py
<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="c2d86dd6-9dbb-444d-a9fe-60b6a510bb6b", element="e1201ceb-4f31-48fb-8630-d46e775fb17a")>
1
https://www.mindphp.com/forums/viewtopic.php?f=338&t=52159&sid=81bf5d776021a4eff9d2271a73d86376 , RoadMap - Mooziicart
2
https://www.mindphp.com/forums/viewtopic.php?f=338&t=53698&sid=81bf5d776021a4eff9d2271a73d86376 , อัพเดด MooZiiCart - อัพเดดข่าวคราวความเครื่อนไหว Change Log / Version History
3
https://www.mindphp.com/forums/viewtopic.php?f=338&t=58392&sid=81bf5d776021a4eff9d2271a73d86376 , ปัญหาที่พบบ่อยในการใช้งาน MooZiicart - Index
4
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71909&sid=81bf5d776021a4eff9d2271a73d86376 , ขอวิธีการหรือขั้นตอนการรันโค้ด selenium สำหรับ ทดสอบ MooZiiCart หน่อยครับ
5
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71678&sid=81bf5d776021a4eff9d2271a73d86376 , เปิดเทมเพจไม่ได้
6
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71270&sid=81bf5d776021a4eff9d2271a73d86376 , มีข้อผิดพลาดเกิดขึ้น 1054 Unknown column 'ordering' in 'field list' แก้ไขยังไงครับ
7
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71358&sid=81bf5d776021a4eff9d2271a73d86376 , เเก้ไขหน้าลงทะเบียน
8
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71331&sid=81bf5d776021a4eff9d2271a73d86376 , อยากอัพ web ขึ้น host ทำไงคะ
9
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71165&sid=81bf5d776021a4eff9d2271a73d86376 , สอบถามการตั้งค่า plugin payment omise
10
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71154&sid=81bf5d776021a4eff9d2271a73d86376 , อยากใส่เมนูข้างๆTemplate ทำยังไงคะ
11
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71034&sid=81bf5d776021a4eff9d2271a73d86376 , เพิ่มเนื้อหาในเมนูแล้วมัน error แก้ยังไงดีคะ
12
https://www.mindphp.com/forums/viewtopic.php?f=338&t=71033&sid=81bf5d776021a4eff9d2271a73d86376 , รายการสินค้าในเว็บไซต์ห่างกันทำไงดีคะ
13
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70904&sid=81bf5d776021a4eff9d2271a73d86376 , ขนาดไซส์กับสีเสื้อให้เลือกต้องเพิ่มส่วนเสริมของ Mooziicart อะไรคะ
14
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70859&sid=81bf5d776021a4eff9d2271a73d86376 , โหลด tempted mooziicart แล้วใช้ไม่ได้ค่ะ
15
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70822&sid=81bf5d776021a4eff9d2271a73d86376 , ใช้ virtuemart บน Joomla 1.5 อัพเกรดมาใช้ MooZiiCart ได้ไหม
16
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70767&sid=81bf5d776021a4eff9d2271a73d86376 , ใช้งาน plugin mzc notify ไม่ได้ครับ
17
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70755&sid=81bf5d776021a4eff9d2271a73d86376 , หน้า admin ของ MooZiicart แก้ template เองได้ไหม
18
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70603&sid=81bf5d776021a4eff9d2271a73d86376 , สอบถามการเปิดใช้งานโมดูล Filters
19
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70562&sid=81bf5d776021a4eff9d2271a73d86376 , สอบถาม วิธี import product เข้า mooziicart
20
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70519&sid=81bf5d776021a4eff9d2271a73d86376 , จะตั้งค่าให้มีระบบเเจ้งการโอนเงินยังไงค่ะ
21
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70507&sid=81bf5d776021a4eff9d2271a73d86376 , ทำเว็บขายของ หลายภาษา เริ่มจากนี่
22
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70497&sid=81bf5d776021a4eff9d2271a73d86376 , สอบถามการเพิ่มสินค้าในบล็อก template ทำยังไงคะ
23
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70430&sid=81bf5d776021a4eff9d2271a73d86376 , อัปเดตเวอร์ชั่น Error
24
https://www.mindphp.com/forums/viewtopic.php?f=338&t=70384&sid=81bf5d776021a4eff9d2271a73d86376 , ติดตั้ง Plugin System MZC Multi Shop ของ mooziicart ไม่ได้
25
https://www.mindphp.com/forums/viewtopic.php?f=338&t=69076&sid=81bf5d776021a4eff9d2271a73d86376 , Module Product Labels แสดงแล้ว error
26
https://www.mindphp.com/forums/viewtopic.php?f=338&t=69946&sid=81bf5d776021a4eff9d2271a73d86376 , ดาวน์โหลด Template Opencart ไม่ได้
<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="c2d86dd6-9dbb-444d-a9fe-60b6a510bb6b", element="5a7756d9-4604-4754-9bde-e4a48b08529f")>
Traceback (most recent call last):
File "/home/com003/PycharmProjects/pythonProject_selenium_test/venv/selenium_openwebtest01.py", line 20, in <module>
save_link[no] = i.get_attribute('href') +' , '+i.text
File "/home/com003/PycharmProjects/pythonProject_selenium_test/venv/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 141, in get_attribute
self, name)
File "/home/com003/PycharmProjects/pythonProject_selenium_test/venv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 636, in execute_script
'args': converted_args})['value']
File "/home/com003/PycharmProjects/pythonProject_selenium_test/venv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/com003/PycharmProjects/pythonProject_selenium_test/venv/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Web element reference not seen before: {"element-6066-11e4-a52e-4f735466cecf":"2849c086-500d-47ec-bdec-acfa6160d2b7"}
Process finished with exit code 1