How python collects Baidu search results with links to specific URL
This article mainly introduces python how to collect Baidu search results with specific URL links, the article is very detailed, has a certain reference value, interested friends must read it!
# coding utf-8import requestsfrom bs4 import BeautifulSoup as bsimport refrom Queueimport Queueimport threadingfrom argparse import ArgumentParserarg = ArgumentParser (description='baidu_url_collet py-script by xiaoye') arg.add_argument ('keyword',help='keyword like inurl:?id=for searching sqli site') arg.add_argument Default=10) arg.add_argument ('- User-Agent':'Mozilla/5.0 (windows NT 10.0 WX64) result = arg.parse_args () headers = {'User-Agent':'Mozilla/5.0 (windows NT 10.0 WX64) Rv:50.0) Gecko/20100101 Firefox/50.0'} class Bg_url (threading.Thread): def _ _ init__ (self,que): threading.Thread.__init__ (self) self._que = que def run (self): while not self._que.empty (): URL = self._que.get () try: self.bd_url_collet (URL) except Exception E: print (e) pass def bd_url_collect (self, url): r = requests.get (url, headers=headers, timeout=3) soup = bs (r.content, 'lxml', from_encoding='utf-8') bqs = soup.find_all (name='a', attrs= {' data-click':re.compile (ritual.') 'class':None}) # get the link to the a tag searched from Baidu for bq in bqs: r = requests.get (bq [' href'], headers=headers, timeout=3) # get the real link if r.status_code = = 200 print r.url with open # if the status code is 200 print r.url with open (result.outfile 'a') as f: f.write (r.url +'\ n') def main (): thread = [] thread_count = result.thread_count que = Queue () for i in range (0 (result.pagecount-1) * 10for i in thread 10): que.put ('https://www.baidu.com/s?wd=' + result.keyword +' & pn=' + str (I)) or i in range (thread_count): thread.append (Bd_url (que)) for i in thread: i.start () for i in thread: i.join () if _ name__ = ='_ main__': main () # execute The format python aaaaa.py "inurl:asp?id="-p 30-t 30 and above are all the contents of the article "how python collects Baidu search results with links with specific URL" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!