简体   繁体   中英

Upload file to Twitter with Selenium Python

I am trying to make a twitter bot and I am using Seleniumwith Python.

I have tried the method from this page: Upload file with Selenium in Python

HTML:

<input accept="image/jpeg,image/png,image/webp,image/gif,video/mp4,video/quicktime,video/webm" multiple="" tabindex="-1" type="file" data-focusable="true" class="r-8akbif r-orgf3d r-1udh08x r-u8s1d r-xjis5s r-1wyyakw" data-testid="fileInput">

Code:

button = driver.find_element_by_xpath('//*[@id='react-root']/div/div/div[2]/main/div/div/div/div/div/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[2]/div/div/div[1]/input')
button.click()
button.send_keys('C://Users/Yagmur/Desktop/TwitterBot/2020-09-21data.png')

I can't upload pictures this code is not working enter image description here

I think that Selenium only works with web page. You could try with requests but it's very difficult to scrape/work with Twitter without Twitter API..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM