使用BeautifoulSoup废弃菜单及其Google分析事件跟踪

时间:2017-04-12 08:18:23

标签: python-3.x beautifulsoup

我正在尝试使用BeautifulSoup废弃我的某个网站(http://www.lagazettedescommunes.com/)的“汉堡菜单”,以获取每个元素的名称及其Google事件跟踪标签

到目前为止,我已成功使用BeautifoulSoup提取菜单中的所有“li”,但我不明白我如何拥有两个列表:一个包含所有标签(与菜单中的顺序相同)和一个包含所有Google事件跟踪标签

到目前为止我的代码:

from urllib.request import urlopen
import os
from bs4 import BeautifulSoup
import csv
import time
import re


url_gaz="http://www.lagazettedescommunes.com/"
page=urlopen(url_gaz)

soup=BeautifulSoup(page)

nav=soup.findAll('li', class_=re.compile("(itemMenu)"))

for li in nav:
    print(li.contents)

os.system("pause")

你知道我怎么能得到我想要的东西吗? (我的两个列表的目标是在此爬行之后调用Google AnalyticsAPI以了解我对此菜单中每个元素的点击次数)

非常感谢你的帮助和时间

0 个答案:

没有答案