简体   繁体   English

使用 Selenium Python 将文件上传到 Twitter

[英]Upload file to Twitter with Selenium Python

I am trying to make a twitter bot and I am using Seleniumwith Python.我正在尝试制作一个 twitter 机器人,我正在使用 Selenium 和 Python。

I have tried the method from this page: Upload file with Selenium in Python我已经尝试过这个页面的方法: 在 Python 中使用 Selenium 上传文件

HTML: 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.我认为 Selenium 只适用于网页。 You could try with requests but it's very difficult to scrape/work with Twitter without Twitter API..您可以尝试使用请求,但在没有 Twitter API 的情况下很难抓取/使用 Twitter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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