看板 Python 關於我們 聯絡資訊
※ 引述《okeyla (小寶)》之銘言: : 我想一次抓取全家便利店全省的商店資訊, : 觀察到是他以每個縣市命名為各自的.php, 然後各縣市商店都在對應的php裡面. : idea是先抓取各縣市的php名稱放入list, : 再以此list帶出各縣市的網頁, 再取出商店資訊. : 目前卡在這兒, 找不著標籤... : import requests : from bs4 import BeautifulSoup : res = requests.get('http://www.allergen.com.tw/famistore.php') : res.encoding = 'utf-8' : #print res.text : soup = BeautifulSoup(res.text) : # 跑個loop挑出famiKeelung.php, famiTaipei.php... etc. : print soup.select('.td') <--- 啊?! : 可以指導一下嗎??? 知道一個頁面當中有兩個table, 一個是廣告, 另一個是要的資料. 但沒有class,沒有id可供soup select... 是不是有妙法把<a href>的內容(i.e., 那些php)取出呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.160.83.246 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1500690769.A.A6B.html
LessonWang: css selector 不是只有class和id選擇器而已啊xd 07/22 11:00
LessonWang: 話說原po怎不想使用lxml的etree以及HTMLParser 07/22 11:00
LessonWang: 搭配瀏覽器的xpath checker 07/22 11:00
LessonWang: 很快就抓的到資料啦xd 07/22 11:00
LessonWang: http://i.imgur.com/9K0wnq3.jpg 07/22 11:00
LessonWang: 這些href屬性值應該是你要的部分吧 07/22 11:03
LessonWang: http://i.imgur.com/n3Ef8Lu.jpg 07/22 11:03
AlaRduTP: http://i.imgur.com/12Cwg4L.png 07/22 11:32