[問題] 不曉得xpath要怎麼下

看板Python作者 (881 forever)時間11年前 (2014/10/12 14:36), 11年前編輯推噓0(008)
留言8則, 3人參與, 最新討論串1/1
對Xpath還不是很熟 想要請教一下大大 以這個網址為例好了 https://www.ptt.cc/bbs/Boy-Girl/M.1413031277.A.CEE.html <div class="push"> <span class="hl push-tag">推 </span> <span class="f3 hl push-userid">m99</span> <span class="f3 push-content">: 之前男友是鐵匠後來變成船長就...</span> <span class="push-ipdatetime">10/11 22:22 </span></div> 假設我想要抓 m99這個網友所屬的 <div class ="push"> 因為在網頁裡<div class ="push">很多個,我想要全部都把他們找出來  那麼我的Xpath要怎麼下比較好呢? -- -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.218.124 ※ 文章網址: http://www.ptt.cc/bbs/Python/M.1413095793.A.FA2.html ※ 編輯: left (140.112.218.124), 10/12/2014 14:39:38

10/12 14:51, , 1F
打開你的chrome console然後http://imgur.com/IY86Sq0
10/12 14:51, 1F

10/12 14:55, , 2F
這樣的方式只能抓到你手動選擇的那個div啊
10/12 14:55, 2F
※ 編輯: left (140.112.218.124), 10/12/2014 14:56:33

10/12 14:58, , 3F
up9cloud大 sorry沒把問題講清楚, 我是要跟m99相關的所有div
10/12 14:58, 3F

10/12 15:58, , 4F
你是用什麼模組?內建的 ElementTree 不支援這種查詢
10/12 15:58, 4F

10/12 15:59, , 5F
python scrapy 2.4
10/12 15:59, 5F

10/12 16:00, , 6F
不然 .//span[contains(text(), 'm99')]/.. 應該可以
10/12 16:00, 6F

10/12 16:01, , 7F
Scrapy 的話上面的應該沒問題, 可以試情況多加判斷
10/12 16:01, 7F

10/12 16:13, , 8F
可以了耶 感謝大大
10/12 16:13, 8F
文章代碼(AID): #1KEY5n-Y (Python)
文章代碼(AID): #1KEY5n-Y (Python)