beauthulsoup不能抓取谷歌搜索结果?

2024-09-27 23:15:53 发布

您现在位置:Python中文网/ 问答频道 /正文

试图在谷歌搜索结果中爬行。这段代码可以很好地与所有其他网站,我尝试过,但没有与谷歌合作。它返回一个空列表。在

from BeautifulSoup import BeautifulSoup
import requests

def googlecrawler(search_term):
    url="https://www.google.co.in/?gfe_rd=cr&ei=UVSeVZazLozC8gfU3oD4DQ&gws_rd=ssl#q="+search_term
    junk_code=requests.get(url)
    ok_code=junk_code.text
    good_code=BeautifulSoup(ok_code)
    best_code=good_code.findAll('h3',{'class':'r'})
    print best_code


googlecrawler("healthkart") 

它应该返回这样的值。在

^{pr2}$

Tags: 代码importurlsearch网站codeokrd
1条回答
网友
1楼 · 发布于 2024-09-27 23:15:53

看着good_code我根本看不到h3或{}。这就是为什么你的代码返回一个空列表。在

您的代码本身没有问题,但是您要搜索的内容并不存在。在

你想回来什么?在

相关问题 更多 >

    热门问题