[ปัญหา] การใช้งาน Selenium แล้วเจอ Error 502 Bad Gateway บน Web Browser

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: [ปัญหา] การใช้งาน Selenium แล้วเจอ Error 502 Bad Gateway บน Web Browser

Re: [ปัญหา] การใช้งาน Selenium แล้วเจอ Error 502 Bad Gateway บน Web Browser

โดย rangsan » 12/05/2018 11:09 am

mindphp เขียน:error นี้เป็นปัญหา ของทางฝั่ง Server
ไม่ใช่ ปัญหาของ selenium

อ่อ ครับขอบคุณครับ ตอนแรกผมนึกว่าจะมีวิธีในการดักในส่วนของ Error นี้

Re: [ปัญหา] การใช้งาน Selenium แล้วเจอ Error 502 Bad Gateway บน Web Browser

โดย mindphp » 12/05/2018 10:59 am

error นี้เป็นปัญหา ของทางฝั่ง Server
ไม่ใช่ ปัญหาของ selenium

[ปัญหา] การใช้งาน Selenium แล้วเจอ Error 502 Bad Gateway บน Web Browser

โดย rangsan » 12/05/2018 10:48 am

การใช้งาน Selenium แล้วเจอ Error 502 Bad Gateway บน Web Browser

ตอนนี้ผมได้ทำ selenium Webdriver ในการสร้างบอทขึ้นมาเพื่อที่จะให้บอทนั้นสามารถเข้าไปคลิกโหวตบทความ ให้กับเว็บ https://www.mindphp.com/ แต่เมื่อบอทเริ่มทำงานคลิกโหวตไปเรื่อย ๆ หน้าเว็บก็จะโหลดนานในการเข้าไปที่บทความถัดไป แล้วก็จะมี Error 502 Bad Gateway ขึ้นมาตัวอย่างเมื่อทำการรันแล้วเกิด Error ขึ้นด้านล่าง

คำสั่งที่ผมใช้ในการวนลูปเพื่อให้บอทเข้าไปยังบทความต่าง ๆมีดังนี้ครับ

โค้ด: เลือกทั้งหมด

# หา Element โดยใช้ Xpath
title_list = driver.find_elements_by_xpath(
    "//div[@class='category-list']//table[@class='category "
    "table table-striped table-bordered table-hover']/tbody/tr//a[@href]")

# นำจำนวนบทความที่มีในหน้านั้น
countRow = len(driver.find_elements_by_xpath(
    "//div[@class='category-list']//table[@class='category table table-striped table-bordered table-hover']/tbody/tr"))
print(countRow)

# นำ Session และ Element มาแปลงเป็นลิ้งค์
link = []
for web_link in title_list:
    link.append(web_link.get_attribute("href"))

print(link)

check = driver.page_source
footer = driver.find_element_by_xpath("//footer/div")
header = driver.find_element_by_xpath("//body/div/div/div")

# ทำการวน loop เพื่อคลิกล้งค์
for web_link in link:
    print(web_link)
    time.sleep(2)
    driver.get(web_link)
    print('-----Open Link------')
    if "header" in check:
        print("หน้าเว็บสมบูรณ์")
    else:
        print("หน้าเว็บไม่สมบูรณ์ ขาด Header")
    if "footer" in check:
        print("หน้าเว็บสมบูรณ์")
    else:
        print("หน้าเว็บไม่สมบูรณ์ ขาด Footer")
    time.sleep(1)
    driver.find_element_by_xpath("//input[@value='เรต']").click()
    time.sleep(1)
    driver.get("https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1/31-"
               "%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%97%E0%B8%B1%"
               "E0%B9%88%E0%B8%A7%E0%B9%84%E0%B8%9B.html")
ภาพตัวอย่าง
จะเห็นได้ว่าบอทนั้นได้คลิกเข้าไปในบทความต่าง ๆ แต่เมื่อผ่านไปสักพักก็จะมีการโหลดหน้าเว็บเพื่อเข้าบทความนานขึ้น
Cooldown.png
จากนั้นก็มี Error ขึ้น ครับ
Error 502.png
อยากรู้ว่ามีวิธีแก้ไขกับ Error ยังไงบ้างครับ

ข้างบน