[英]How to query with time filters in GoogleScraper?
即使Google的官方API不在查詢結果中提供時間信息-即使沒有針對關鍵字的時間過濾,高級搜索中也有時間過濾選項:
GoogleScraper庫提供了許多與時間相關的靈活選項。 如何使用庫添加時間功能?
經過一番檢查后,我發現Google將qdr
值的過濾信息發送到tbs
鍵的time based search
(可能是time based search
盡管未正式說明):
https://www.google.com/search?tbs=qdr:h1&q=stackoverflow
這將獲取過去一個小時的結果。 m
和y
字母分別可以使用幾個月和幾年。
另外,要添加按日期排序功能,請同時添加sbd
(應表示sort by date
)值: https : //www.google.com/search? sbd
, sbd
:1 & sbd
我能夠將這些關鍵字插入GoogleScraper的BASE Google URL。 在下面插入線的端部get_base_search_url_by_search_engine()
方法(只是之前return
在) scraping.py
:
if("google" in str(specific_base_url)):
specific_base_url = "https://www.google.com/search?tbs=qdr:{},sbd:1".format(config.get("time_filter", ""))
現在,在您的配置中使用time_filter
選項:
from GoogleScraper import scrape_with_config
config = {
'use_own_ip': True,
'keyword_file': "keywords.txt",
'search_engines': ['google'],
'num_pages_for_keyword': 2,
'scrape_method': 'http',
"time_filter": "d15" #up to 15 days ago
}
search = scrape_with_config(config)
結果將僅包括時間范圍。 此外,結果中的文本片段將具有原始日期信息:
one_sample_result = search.serps[0].links[0]
print(one_sample_result.snippet)
4分鍾前這一定很容易-讓propertytotalPriceOfOrder = order.items.map(item => + item.unit * + item.quantity * + item.price);。 其中order是您的整個json對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.