ZEOS

Địa chỉ IP của bạn: 18.222.67.251
Độ phân giải màn hình:x

Website đã chạy được 1484 ngày

Thiện - Công Nghệ Thông Tin

Trang web chia sẻ kinh nghiệm đọc, học tập, làm việc và giảng dạy của bản thân nhằm giúp mọi người có duyên ghé thăm thì có tư liệu để học tập, nghiên cứu.
Site Map Contacts Home
Hide ad unit

ĐĂNG KÝ/ĐĂNG NHẬP

QUẢNG CÁO

Advertising

BÌNH CHỌN

Bạn thích Hệ thống quản lý nội dung hay CMS (Content Management System) nào

Các khảo sát khác...

QUẢNG CÁO

Advertising

THẺ

QUẢNG CÁO

Advertising

THỐNG KÊ

{siteinfo} {prostats} {online}
{referer}
ThienCNTT » Lập trình Python » Mã nguồn Python sử dụng Pandas để duyệt qua từng dòng trong Google Sheet và mở link bằng Chrome
AuthorAuthor: admin | DateDate: 23-01-2024, 22:59
from ast import If, IfExp
import webbrowser
import pandas as pd
from time import sleep

# https://docs.google.com/spreadsheets/d/1wiDhK4DnADdto6W2zY9nvYkUxsoSM8HjpMSGWV67V_Y/edit#gid=0

#get spreadsheets key from url
gsheetkey = "1wiDhK4DnADdto6W2zY9nvYkUxsoSM8HjpMSGWV67V_Y"
#sheet name
sheet_name = 'LINK'


# STT	Link	                   Profile
# 1	  https://thiencntt.com	   Profile 1
# 2	  https://vnexpress.net	   Profile 1
# 3	  https://tuoitre.vn  	   Profile 2



url=f'https://docs.google.com/spreadsheet/ccc?key={gsheetkey}&output=xlsx'
exDataDf = pd.read_excel(url,sheet_name=sheet_name)

numLink = exDataDf.shape[0]
numNewLink = numLink
# print(numLink)

# Windows
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'

# Mở link ở cmd để coi danh sách profile
# "C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data"


for i in range(0, numLink):
  sleep(2)
  print(exDataDf.iloc[i]["Link"])
  if type(exDataDf.iloc[i]["Profile"]) == str:
    profile = exDataDf.iloc[i]["Profile"]
  else:
    profile = "Default"
  webbrowser.get(chrome_path + ' --profile-directory="{}" %s'.format(profile)).open(exDataDf.iloc[i]["Link"])



# khi mở code thì chạy các lệnh trên lần đầu để có số lượng link, mở các link đã có
# Vào vòng lặp while để check có link mới không

print("Vao vong lap While")
while numNewLink <= numLink: # Nếu số lượng link mới <= số lượng link cũ thì vào vòng lặp để check
  print("Wait 10 second")
  sleep(10) # Ngưng 10 giây và check lại
  exDataDfNew = pd.read_excel(url,sheet_name=sheet_name)
  print(exDataDfNew.shape[0])
  numNewLink = exDataDfNew.shape[0]

  # Tiến hành mở các link mới
  if numNewLink > numLink:
    for j in range(numLink, numNewLink):
      sleep(2)
      if type(exDataDfNew.iloc[j]["Profile"]) == str:
        profile = exDataDfNew.iloc[j]["Profile"]
      else:
        profile = "Default"
      print(profile)
      webbrowser.get(chrome_path + ' --profile-directory="{}" %s'.format(profile)).open(exDataDfNew.iloc[i]["Link"])
    numLink = numNewLink # Nếu số lượng link mới lớn hơn thì gán số lượng link cũ = link mới

Dear visitor, you went to the site as unregistered user. We encourage you to register or enter the site under your name.

Thêm bình luận

Name:*
E-Mail:*
Security Code
Enter Code:*
Nhấp vào hình ảnh để cập nhật mã nếu bạn không đọc được.
 


️️ 🍂️️ 💝 ️️ 🌟