您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用Python在Google中搜索

使用Python在Google中搜索

并不是我一直在寻找的东西,但是我发现自己现在是一个不错的解决方案(如果我可以做得更好的话,我可以对其进行编辑)。我像在Google中一样搜索(仅返回URL)和Beautiful Soup软件包结合在一起来解析HTML页面

from google import search
import urllib
from bs4 import BeautifulSoup

def google_scrape(url):
    thepage = urllib.urlopen(url)
    soup = BeautifulSoup(thepage, "html.parser")
    return soup.title.text

i = 1
query = 'search this'
for url in search(query, stop=10):
    a = google_scrape(url)
    print str(i) + ". " + a
    print url
    print " "
    i += 1

这给了我页面标题链接的列表。

一个很棒的解决方案:

from google import search
import requests

for url in search(ip, stop=10):
            r = requests.get(url)
            title = everything_between(r.text, '<title>', '</title>')
python 2022/1/1 18:37:04 有246人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶