[英]Python replace javascript double quotes in javascript code
我正在嘗試讓Selenium Webdriver執行以下javascript
document.querySelector('#location > input[type="text"]').value="10001"
但是當我使用
execute_script("document.querySelector('#location > input[type="text"]').value="10001"")
由於引號,它無法運行,如何轉義引號?
使用反斜杠將引號內的引號轉義:
execute_script("document.querySelector('#location > input[type=\"text\"]').value = \"10001\"')
順便說一句,在這種情況下,您實際上並不需要額外的引號。 這也將起作用:
execute_script("document.querySelector('#location > input[type=text]').value = 10001')
您是否嘗試過使用三個引號?
execute_script("""document.querySelector('#location > input[type="text"]').value="10001" """)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.