我正在尝试发送带有Chrome
扩展名DHC
https://chrome.google.com/webstore/detail/dhc-resthttp-api-client/aejoelaoggembcahagimdiliamlcdmfm?hl=en的 POST 请求(我知道有很多工具可以发送http
请求,但我需要使用这个)。我写了以下代码:
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
# Add Option to be able to use DHC extension
chrome_options = Options()
chrome_options.add_extension('/usr/lib/firefox/browser/extensions/aejoelaoggembcahagimdiliamlcdmfm-0.8.6.2-www.Crx4Chrome.com.crx')
# Start browser session
dr = webdriver.Chrome(chrome_options=chrome_options)
# Open Extension page
dr.get('chrome-extension://aejoelaoggembcahagimdiliamlcdmfm/dhc.html')
# Close update pop-up if exists
try:
dr.find_element_by_xpath('//a[@class="btn btn-info"]').click()
except:
pass
# Change HTTP request type to POST
request_type = dr.find_elements_by_xpath('//input[@class="gwt-TextBox"]')[1]
request_type.clear()
request_type.send_keys("POST")
# Choose body type 'file'
dr.find_element_by_xpath('//div[@class="pane-head"]').click()
dr.find_elements_by_xpath('//li[@class="dropdown right"]')[1].click()
dr.find_element_by_xpath('//a[contains(text(), "file")]').click()
# Set path to file I want to send
dr.find_element_by_xpath('//input[@class="gwt-FileUpload"]').send_keys('/path/to/file/dummy3gb')
上传文件的最后一步名称出现后,但实际文件大小为 0 字节,我无法发送请求,因为无法识别内容, 而如果从上传提示中手动选择文件,则显示正确的文件大小,我可以发送请求
难道我做错了什么?有任何想法吗?