这是html代码:
<ul>
<li><a href="brands/acapulco-gold/141120">Acapulco Gold</a></li>
<li><a href="brands/adam-lister/141223">Adam Lister</a></li>
<li><a href="brands/adidas-x-raf-simons/125513">adidas x RAF SIMONS</a></li>
我想提取 10Deep
、Acapulco Gold
等品牌,我该怎么做?
最佳答案
我无法使用 Beautifulsoup 做到这一点,但在等待其他答案时...您可以阅读每一行并检索您想要的文本
import urllib
import re
source = urllib.urlopen("https://www.jackthreads.com/ca/brands")
lines = source.readlines()
brand = []
for link in lines[1797:2121]:
find = re.findall(r'<li><a href="brands[^>]*?>(.*?)</a>', link)
if len(find) > 0:
brand.append(find[0])
print(brand[0:12])
#>['10Deep', 'Acapulco Gold', 'Adam Lister', 'AdNArt', 'Afends', 'Akomplice', 'Akribos XXIV', 'Alistare', 'Alpha Beta', 'Alpha Industries', 'Altamont', 'Alternative']
关于python - 美汤提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29523880/