我想解析此頁上具有相同層次結構的所有鏈接。我沒有得到任何回溯,但沒有獲得數據。Python 2.7美麗的湯 - 解析鏈接列表
我試圖從代碼高亮部分得到href標記:
我當前的代碼是:
def link_parser(soup,itemsList):
for item in soup.findAll("div", { "class" : "tileInfo" }):
for link in item.findAll("a", { "class" : "productClick productTitle" }):
try:
itemsList.put(removeNonAscii(html_parser.unescape(link.string)).replace(',',' ')+","+clean_a_url(link['href']))
except Exception:
print "Formatting error: "
traceback.print_exc(file=sys.stdout)
return ""
你不應該給圖像鏈接。從圖像中「複製粘貼」是不可能的。 – 2014-09-25 16:53:24
你需要什麼數據?爲什麼'removeNonAscii'和'clean_a_url'?你不需要使用html編碼的字符串,BeautifulSoup已經爲你做了,你可以使用'link.text'來訪問非轉義的文本。 – 2014-09-25 16:53:59
我需要在href從這個標籤: 我使用clean_a_url因爲我需要url的一致性和清潔性,我使用removeNonAscii,因爲有時我的網址中會有NonAscii字符。 你能告訴我一個使用link.text訪問非轉義文本的例子嗎? – user3677501 2014-09-25 17:03:50