亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

網頁抓取 Google Domains

網頁抓取 Google Domains

肥皂起泡泡 2021-12-17 14:45:22
我試圖從前 100 個結果中獲取域列表:例如:abc.com/xxxx/dddd 域應該是:abc.com我正在使用以下代碼:import timefrom bs4 import BeautifulSoupimport requestssearch=input("What do you want to ask: ")search=search.replace(" ","+")link="https://www.google.com/search?q="+searchprint(link)headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}source=requests.get(link, headers=headers).textsoup=BeautifulSoup(source,"html.parser")soup=BeautifulSoup(source,"html.parser")但是,我不知道如何僅選擇域,也不知道如何指定 100 個結果。當我寫soup.text我只得到:'te - Pesquisa Google(function(){window.google={kEI:\'jsCaXM3AHM6g5OUP4eyT2A0\',kEXPI:\'31\',authuser:0,kscs:\'c9c918f0_jsCaXM3AHM6g5OUP4eyT2A0\',kGL:\'BR\'};google.sn=\'web\';google.kHL=\'pt-BR\';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var b;a&&(!a.getAttribute||!(b=a.getAttribute("eid")));)a=a.parentNode;return b||google.kEI};google.getLEI=function(a){for(var b=null;a&&(!a.getAttribute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b};google.https=function(){return"https:"==window.location.protocol};google.ml=function(){return null};google.time=function()
查看完整描述

1 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

獲得 100 個結果


您必須逐頁抓取,直到它有 100 個結果。假設 要廢棄的關鍵字beautiful+girls URL 適用于像這樣的第 2 頁https://www.google.com/search?q=beautiful+girls&start=10


僅獲取域


首先,您必須使用“srg”類獲取所有 div(查看源代碼后,我看到所有鏈接都在此)


srg_divs = soup.findAll("div", {"class": "srg"})

然后你會發現所有的標簽


out = ''

for div in srg_divs:

    links = div.find_all('a', href=True)

    for a in links:

        # url to domain

        parsed_uri = urlparse(a['href'])

        domain = '{uri.netloc}'.format(uri=parsed_uri)

        # exclude googleusercontent.com

        if 'googleusercontent' in domain or domain == '':

            continue

        out += domain + '\n'


查看完整回答
反對 回復 2021-12-17
  • 1 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號