繁体   English   中英

使用python从Google解析HTML

[英]Parsing html from google with python

我在用python解析google的html源时遇到问题

def events():
    location = sys.argv[1];
    url = "https://www.google.com/search?client=firefox-b-d&q=evenementen+" + location;
    event = requests.get(url=url)
        print("De zoekterm is leeg, probeer het opnieuw")
    soup_events = BeautifulSoup(event.text, 'html.parser')
    events_google = soup_events.find_all('<a class="rl_item rl_item_base" tabindex="0" href="/search?client=firefox-b-d')
    print(type(events_google))
    print(len(events_google))
    print(events_google)

我尝试过: events_google = soup_events.find_all('div', 'BNeawe tAd8D AP7Wnd')起作用了,但是当我尝试其他任何值时,它会输出0,但是当我尝试打印事件时,所有要打印的值都会显示出来。文字,我不确定我在做什么错。 当我运行上面的代码时,我得到以下响应:

<class 'bs4.element.ResultSet'>
0
[]


我实际上是在寻找Google搜索中显示的事件。

嗯,我想你的问题是

events_google = soup_events.find_all('<a class="rl_item rl_item_base" tabindex="0" href="/search?client=firefox-b-d')

应该

events_google = soup_events.find_all("a", 
        {"class" : ["r1_item", " r1_item_base"]})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM