forked from 5ec1cff/TrickyStore
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathget_gh_default_setup.py
More file actions
34 lines (31 loc) · 1.06 KB
/
get_gh_default_setup.py
File metadata and controls
34 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import urllib.request
import urllib.parse
import json
query = 'how to disable default setup codeql api'
url = f"https://html.duckduckgo.com/html/?q={urllib.parse.quote(query)}"
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
try:
html = urllib.request.urlopen(req).read().decode('utf-8')
import re
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def __init__(self):
super().__init__()
self.text = []
self.capture = False
def handle_starttag(self, tag, attrs):
if tag == 'a':
for attr in attrs:
if attr[0] == 'class' and 'result__snippet' in attr[1]:
self.capture = True
def handle_data(self, data):
if self.capture:
self.text.append(data)
def handle_endtag(self, tag):
if tag == 'a':
self.capture = False
parser = MyHTMLParser()
parser.feed(html)
print(" ".join(parser.text))
except Exception as e:
print(e)