我正在使用此代码在网页中打印链接
wb = mechanize.Browser()
wb.open("https://example.com")
print wb.response().read()
for link in wb.links():
print "aa->"
答案如下:
...
<a href=/Router/moneyReload.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Recarga De Saldo</a><br><a href=/Router/roamingMoneyReload.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Recarga en Roaming</a><br><a href=/Router/lastOperatorSale.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Ultima Recarga</a><br><a href=/Router/LastSubscriberTopUpPerform.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Consulta de Recarga</a><br><a href=/Router/stockReportCreditLimit.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Informe de Ventas</a><br><a href=/Router/stockReport.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Informe de Saldo Disponible</a><br><a href=/Router/dealerCloseBatch.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Cierre de Turno</a><br><a href=/Router/ChangePointOfSalePin.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Cambiar PIN</a><br><a href=/Router/activePortfolioQuery.web;JSESSIONID=2C832E9B3DB0EE7162D7434FC352B85E.coreAR02>Consulta Portfolio</a><br></body></html>
如你所见,那里有一些链接,但我没有在'for'中找到任何链接
也许是因为他们在href属性中没有任何引号。但在这种情况下我怎么读它们?
感谢
答案 0 :(得分:0)
迭代时不打印链接。
这有效:
wb = mechanize.Browser()
wb.open("https://example.com")
for link in wb.links():
print link