from bs4 import BeautifulSoup import requests, urllib from datetime import date import re while True: link = "https://www.google.com.mx/search?biw=1535&bih=799&tbm=nws&q=%22New+Strong+Buy%22+site%3A+zacks.com&oq=%22New+Strong+Buy%22+site%3A+zacks.com&gs_l=serp.3...1632004.1638057.0.1638325.24.24.0.0.0.0.257.2605.0j15j2.17.0....0...1c.1.64.serp..8.0.0.Nl4BZQWwR3o" r = requests.get(link) soup = BeautifulSoup(r.text,"html.parser") link = "https://www.google.com.mx/search?biw=1535&bih=799&tbm=nws&q=%22New+Strong+Buy%22+site%3A+zacks.com&oq=%22New+Strong+Buy%22+site%3A+zacks.com&gs_l=serp.3...1632004.1638057.0.1638325.24.24.0.0.0.0.257.2605.0j15j2.17.0....0...1c.1.64.serp..8.0.0.Nl4BZQWwR3o" fetch_data =requests.get(link) content = str((fetch_data.content)) Months = ["January","February","March","April","May","June","July","August","September","October","November","December"] today = date.today() A= ("%s %s" % (Months[today.month - 1],today.day)) a=today.day B= A in content if B == True: B = ("%s %s" % (Months[today.month - 1], a)) else: while B == False: a = a - 1 B = ("%s %s" % (Months[today.month - 1], a)) search = B print("Stocks for {}".format(search)) result = None for i in soup.findAll('h3'): linkText = i.getText() if search in linkText: result = i.find('a').get('href') result = result.split('?')[-1] result = urllib.parse.parse_qs(result)['q'][0] break fetch_dota =requests.get(result) cantent = str((fetch_dota.content)) tickers= "tickers :" pd = "publish_date :" Z= ("%s(.*)%s" % (tickers,pd)) resalt = re.search(Z, cantent) tickerst = resalt.groups()[0] print (re.findall(r'\[.*?\]', tickerst)[0].split("\\'")[1::2]) y=input("\n"+"Press any key except space to restart") if not y: break
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question