-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter.py
More file actions
31 lines (24 loc) · 1.04 KB
/
twitter.py
File metadata and controls
31 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Created by: Owlcept
from playwright.sync_api import sync_playwright
def twitter_scrape(tweet, num_com=9):
with sync_playwright() as p:
#Must use firefox // Other chromium wont load tweets
browser = p.firefox.launch()
context = browser.new_context()
page = context.new_page()
page.goto(tweet)
#Debug tweet below
#page.goto('https://twitter.com/domiono/status/1538891392583450629')
#Title Screenshot
page.locator('data-testid=tweet').screenshot(path="Twitter_Scrape/assets/title.png")
x = page.locator('data-testid=tweet')
y = page.locator('data-testid=tweetText')
#Use 1 as start for skipping title
for i in range(1,num_com):
if i==3:
#Skip the 3rd screenshot because of signup banner
continue
#This colects the text(does not grab emoji
print(y.nth(i).text_content())
x.nth(i).screenshot(path = f'Twitter_Scrape/assets/title{i}.png')
browser.close()