Python 网络抓取 - 搜索 Google EAN 结果(包含 13 个字母的数字)

Python webscraping - search Google result for EAN (number with 13 letters)

我有一个带有代码的工具,我已经可以显示 google 搜索结果文本:

url = "https://www.google.com/search?q=%22ean%22+%22Rowenta%20X-Plorer%20Serie%2075%20RR7687%22&client=firefox-b-d&ei=8W5cYdi-Kc-ckgW-54LIDA&ved=0ahUKEwiY-_zeyrPzAhVPjqQKHb6zAMkQ4dUDCA0&uact=5&oq=%22ean%22+%22Rowenta%20X-Plorer%20Serie%2075%20RR7687%22"
            f = s.get(url)
            eanfield = f.html.xpath(
                '//*[@id="center_col"]', first=True)
            ean = eanfield.text

我想在搜索“ean”“产品标题”时过滤掉通常显示在搜索结果中的 EAN

Ean是一个精确的13个字母的数字,这就是为什么我只需要从文本结果中过滤出一定长度的数字。如何实现?

这样试试:

efs = f.html.xpath('//span[em["EAN"]]')
for ef in efs:
    print(ef.text.split("EAN: ")[1][:13])

输出:

3221616001114
3221616001220
3221616001114
3221616001114
8710103792925
7332543577989
3221614006807
3221614003868