我通过正则表达式和beautifulsoup获得了以下内容。我需要提取 UID 值,例如 5968723334。
[u'/home.html', u'browse_settings.html', u'browse.html?', u'test.html?uid=5415292833', u'test.html?uid=5968723334', u'test.html?uid=5968723334', u'test.html?uid=5453943714', u'test.html?uid=5453943714', u'test.html?uid=6740871094', u'test.html?uid=6740871094', u'test.html?uid=5991868792', u'test.html?uid=5991868792', u'test.html?uid=25072413', u'test.html?uid=25072413', u'test.html?uid=6739965683', u'test.html?uid=6739965683', u'test.html?uid=7272910004', u'test.html?uid=7272910004', u'test.html?uid=13179298', u'test.html?uid=13179298', u'test.html?uid=5392816266', u'test.html?uid=5392816266', u'test.html?uid=5992588819', u'test.html?uid=5992588819', u'test.html?uid=6727114420', u'test.html?uid=6727114420', u'test.html?uid=7263648884', u'test.html?uid=7263648884', u'test.html?uid=5447240210', u'test.html?uid=5447240210', u'test.html?uid=5460515002', u'test.html?uid=5460515002', u'test.html?uid=5400731231', u'test.html?uid=5400731231', u'browse.html?params=_F_18_24_GB_0___grid_1', u'/home.html?t=1374068507', u'/account_info.html', u'http://www.example.com/browse.html?params=_F_18_24_GB_0___grid_0', u'http://www.example.com/contact.html', u'/logout.html', u'#top', u'/terms_of_service.html', u'http://safety.example.com']
我已经设法像这样提取了一个“uid”,但是我想提取所有的 UID:
>>> m = re.search("uid=(\d*)", soup.contents[0])
>>> print m
<_sre.SRE_Match object at 0x211b210>
>>> print m.group(1)
5442562712
请帮忙!