iT邦幫忙

0

python 爬蟲網頁資料時無法遇到 type="hidden" 時無法send value 成功

詢問各位大大 ><
我的問題:我想要在網頁先下關鍵字點查詢後,再去爬文回來。但在下關鍵字給條件值的時候遇到一個問題。只要是這種type="hidden" 類型的,我用send_keys都是沒有效果。
這邊該如何調整呢

例如我想在[希望工作地點]輸入高雄市
https://ithelp.ithome.com.tw/upload/images/20220119/20145896BFSFGejI9E.png
點完後後,XML呈現的是如下及我的程式碼:
https://ithelp.ithome.com.tw/upload/images/20220119/201458969qBBRSz3C3.png

看更多先前的討論...收起先前的討論...
jiatool iT邦研究生 4 級 ‧ 2022-01-19 21:18:03 檢舉
這是哪個網站啊?
obarisk iT邦研究生 2 級 ‧ 2022-01-20 09:49:51 檢舉
改用 click ?
what0208 iT邦新手 5 級 ‧ 2022-01-20 09:56:10 檢舉
大家好,是104vip企業網的網站。如果用click該怎麻給它值呢?之前有用過js的方式,但不確定用法。有人可以針對這個提供我解法嗎?
ddx iT邦研究生 5 級 ‧ 2022-01-20 10:55:14 檢舉
試試看
driver.execute_script("document.getElementById('搜尋欄位').value=你要的值")
jiatool iT邦研究生 4 級 ‧ 2022-01-20 21:32:00 檢舉
或者不要用Selenium瀏覽器操作,看能不能找出它送出的請求
(類似我之前寫的這篇:https://blog.jiatool.com/posts/job104_spider/)
what0208 iT邦新手 5 級 ‧ 2022-01-22 08:26:51 檢舉
感謝各位,其實是有值的,在原程式碼裡有值進去,只是畫面沒有。我試過查詢下來的結果,是有效的,謝謝大家!
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
I code so I am
iT邦高手 1 級 ‧ 2022-01-20 11:03:26
最佳解答
driver.execute_script("document.getElementById('comment-user').value='600000'")

可參閱 https://pythonbasics.org/selenium-execute-javascript/

看更多先前的回應...收起先前的回應...
what0208 iT邦新手 5 級 ‧ 2022-01-22 08:19:56 檢舉

我試了你提供的方式後,原始碼是有儲存到值,但畫面沒有產生。這樣算是有效的值嗎https://ithelp.ithome.com.tw/upload/images/20220122/20145896IiEYTOSfr1.png

what0208 iT邦新手 5 級 ‧ 2022-01-22 08:27:11 檢舉

感謝I code so I am,其實是有值的,在原程式碼裡有值進去,只是畫面沒有。我試過查詢下來的結果,是有效的,謝謝大家!

/images/emoticon/emoticon03.gif
水啦。

what0208 iT邦新手 5 級 ‧ 2022-01-22 13:29:35 檢舉

抱欠,我又遇卡住另一個問題了,如下圖,如果是option的方式是多個數值的,讓怎麻給它呢https://ithelp.ithome.com.tw/upload/images/20220122/20145896rwqPXlRCIP.png

# 找到 select tag
ele_select = driver.find_element_by_css_selector("select[name='sm']")

# 以 value 指定選項
Select(ele_select).select_by_value("2")

參閱 https://www.itread01.com/content/1548946118.html

what0208 iT邦新手 5 級 ‧ 2022-01-24 15:16:07 檢舉

hi我用這個語法,會出現定位不到元素。
invalid selector: An invalid or illegal selector was specified
我試了以下:
https://ithelp.ithome.com.tw/upload/images/20220124/20145896EMXychbv3R.png

我覺的這網頁的多選項跟一般的下拉式不太一樣。
提供網頁原始碼給你看看。
圖一:未點選的畫面
https://ithelp.ithome.com.tw/upload/images/20220124/20145896pmNdKR6ZQ9.png
圖二:點選畫面,選完項目後,直接按方框中右上的x,值就會自動進去。
https://ithelp.ithome.com.tw/upload/images/20220124/20145896nx5VutJl8I.png
圖三:點選完後的畫面
https://ithelp.ithome.com.tw/upload/images/20220124/20145896nNYLe0wPjZ.png

what0208 iT邦新手 5 級 ‧ 2022-01-27 16:25:36 檢舉

hi I code so I am
我試過以下二種,都會出現無法把值存入
Could not locate element with visible text: FLPT(English)
Cannot locate option with value: 4006001003
https://ithelp.ithome.com.tw/upload/images/20220127/201458969a5jeXaSS7.png
https://ithelp.ithome.com.tw/upload/images/20220127/20145896bIxPU6WDTc.png

我補充一下,選取項目後和之後的原始碼,能不能看出不一樣的地方

(這是未選任何項目,而且這邊是可以多選的)
https://ithelp.ithome.com.tw/upload/images/20220127/201458962ZtNlMRqjV.png

這邊是選完項目後,它才會自動出現value的值出來。
https://ithelp.ithome.com.tw/upload/images/20220127/20145896HFrhfP8KkN.png

我要發表回答

立即登入回答