|
26 | 26 | from lib.core.settings import BING_REGEX |
27 | 27 | from lib.core.settings import DUCKDUCKGO_REGEX |
28 | 28 | from lib.core.settings import DUMMY_SEARCH_USER_AGENT |
29 | | -from lib.core.settings import GOOGLE_CONSENT_COOKIE |
30 | | -from lib.core.settings import GOOGLE_REGEX |
31 | 29 | from lib.core.settings import HTTP_ACCEPT_ENCODING_HEADER_VALUE |
32 | 30 | from lib.core.settings import SEARCH_ABUSE_MARKERS |
33 | 31 | from lib.core.settings import UNICODE_ENCODING |
@@ -91,19 +89,20 @@ def _search(dork): |
91 | 89 | requestHeaders = { |
92 | 90 | HTTP_HEADER.USER_AGENT: dict(conf.httpHeaders).get(HTTP_HEADER.USER_AGENT, DUMMY_SEARCH_USER_AGENT), |
93 | 91 | HTTP_HEADER.ACCEPT_ENCODING: HTTP_ACCEPT_ENCODING_HEADER_VALUE, |
94 | | - HTTP_HEADER.COOKIE: GOOGLE_CONSENT_COOKIE, |
95 | 92 | } |
96 | 93 |
|
97 | 94 | gpage = conf.googlePage if conf.googlePage > 1 else 1 |
98 | 95 | logger.info("using search result page #%d" % gpage) |
99 | 96 |
|
100 | 97 | encoded = urlencode(dork, convall=True) |
101 | 98 |
|
102 | | - # Note: (name, url, POST data, regex, regex flags, match->link). Ordered by current scraping reliability; tried in turn until one yields results (DuckDuckGo currently being the only consistently scrapeable one) |
| 99 | + # Note: DuckDuckGo's first result page holds 10 entries, while each subsequent one holds 15 (hence the non-linear offset) |
| 100 | + ddgOffset = 0 if gpage == 1 else 10 + (gpage - 2) * 15 |
| 101 | + |
| 102 | + # Note: (name, url, POST data, regex, regex flags, match->link). Ordered by current scraping reliability; tried in turn until one yields results (Google is not in here as it serves results only to JavaScript capable clients) |
103 | 103 | engines = ( |
104 | | - ("DuckDuckGo", "https://html.duckduckgo.com/html/", "q=%s&s=%d" % (encoded, (gpage - 1) * 30), DUCKDUCKGO_REGEX, re.I | re.S, lambda match: match.group(1).replace("&", "&")), |
| 104 | + ("DuckDuckGo", "https://html.duckduckgo.com/html/", "q=%s&s=%d" % (encoded, ddgOffset), DUCKDUCKGO_REGEX, re.I | re.S, lambda match: match.group(1).replace("&", "&")), |
105 | 105 | ("Bing", "https://www.bing.com/search?q=%s&first=%d" % (encoded, (gpage - 1) * 10 + 1), None, BING_REGEX, re.I | re.S, lambda match: decodeBase64(match.group(1), binary=False) if match.group(1) else match.group(2).replace("&", "&")), |
106 | | - ("Google", "https://www.google.com/search?q=%s&num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search&start=%d" % (encoded, (gpage - 1) * 100), None, GOOGLE_REGEX, re.I, lambda match: match.group(1) or match.group(2)), |
107 | 106 | ) |
108 | 107 |
|
109 | 108 | for name, url, data, regex, flags, extract in engines: |
|
0 commit comments