in firefox, but after 5 or 10 tab jump to latest tab, how to fix this?
import pyautogui
import pyperclip
import time
def copy_text_from_tabs(num_tabs, output_file):
# Delay to ensure you have time to focus on Firefox
print("Please focus on Firefox within the next 5 seconds...")
time.sleep(5)
# List to store the text from each tab
tab_texts = []
# Loop through the number of tabs specified
for tab_num in range(1, num_tabs + 1):
# Switch to the tab
pyautogui.hotkey('ctrl', str(tab_num))
# Delay to allow time for the page to load
time.sleep(1)
# Select all text, copy, and append to the list
pyautogui.hotkey('ctrl', 'a')
pyautogui.hotkey('ctrl', 'c')
tab_text = pyperclip.paste()
tab_texts.append(f"Tab {tab_num}:\n{tab_text}\n{'/' * 25}\n") # Add separators between tab texts
# Join all the tab texts
all_text = '\n'.join(tab_texts)
# Save the text to the output file
with open(output_file, 'w', encoding='utf-8') as file:
file.write(all_text)
if name == "main":
num_tabs_to_copy = 20 # Change this number to the desired number of tabs
output_file_name = "all_tabs_text.txt"
copy_text_from_tabs(num_tabs_to_copy, output_file_name)
!paetebin
!paste
To post more than a few lines of code, use a pastebin like: * dpaste.org * linkode.org * bin.kv2.dev * hastebin.com If you are stuck in a terminal, you can use ix.io or paste.rs to paste from the CLI: <command to print output> |& curl -F 'f:1=<-' ix.io <command to print output> |& curl --data-binary @- https://paste.rs
you can add a condition to check whether the current tab number is a multiple of 5 or 10. If it is, then switch to the latest tab before proceeding to the next iteration
I guess your problem is that, instead of going to the 9th tab your code goes to the last tab. That's because "Ctrl - 9" is the shortcut for the last tab not the 9th tab. Instead switch tabs with "Ctrl - Tab"
can you tell me what change i must apply to my script?
Where you're iterating with tab_num, that's where you should ctrl+tab
Обсуждают сегодня