0
我試圖從site使用python通過使用urlib掃描頁面和使用正則表達式查找代理來獲取代理。Python的正則表達式問題
頁面上的代理服務器看起來是這樣的:
<a href="/ip/190.207.169.184/free_Venezuela_proxy_servers_VE_Venezuela">190.207.169.184</a></td><td>8080</td><td>
我的代碼如下所示:
for site in sites:
content = urllib.urlopen(site).read()
e = re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\<\/\a\>\<\/td\>\<td\>\d+", content)
#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+
for proxy in e:
s.append(proxy)
amount += 1
正則表達式:
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\<\/\a\>\<\/td\>\<td\>\d+
我知道代碼工作,但正則表達式是錯誤的。
有關如何解決此問題的任何想法?編輯:http://www.regexr.com/似乎事情我的正則表達式很好?
直視'lxml'或'beautifulsoup'。使用正則表達式的HTML是一個黑客攻擊。 – 2014-10-04 18:08:18
請勿轉義'<,>,a,http://regex101.com/r/xB5sT0/2 – 2014-10-04 18:10:17
請參閱http://stackoverflow.com/questions/26183643/find-specific-text-in-beautifulsoup/ 26183877#26183877 – 2014-10-04 18:11:55