通过Twilio API进行网络抓取并发送到我的手机

问题描述

我是Python网络抓取的新手,我正试图通过Twilio将我从barchart.com抓取的信息发送到我的手机(Whatsapp)。这是下面的代码,我该如何执行我的想法?

//Optionisto.py:name of the scraping file 
from bs4 import BeautifulSoup
from twilio.rest import Client
import requests


source = requests.get('https://www.marketbeat.com/market-data/unusual-call-options-volume/').text

soup = BeautifulSoup(source,'html.parser')
#print(soup.prettify())

title = soup.find('title').text.strip()
#print(title)

table = soup.find('table')
#print(table.prettify())
 
account_sid = 'AC4c6710f0a0f0fba4e2d6be2442e228da' 
auth_token = 'REDACTED' 
client = Client(account_sid,auth_token) 
def send_alert():
    message = client.messages.create( 
                              from_='whatsapp:+14155238886',body='Your appointment is coming up on July 28 at 3PM',to='whatsapp:+10000000000' 
                          ) 
    print(message.sid)
    for stock in table.find_all('tbody'):
        rows = stock.find_all('tr')
        for row in rows:
            cells = row.find_all('td')
            pira = row.find_all('td')[3].text
            reason = row.find_all('td')[5].text
            #print(pira)
            for transport in cells:
                links = transport.find_all('a',class_ = 'no-underline')
                for identifier in links:
                    ticker = identifier.find('div',class_ = 'ticker-area').text
                    print(' ')
                    print(ticker,pira,reason)

//Clock.py name of the scheduling file
    from apscheduler.schedulers.blocking import BlockingScheduler
from Optionisto import send_alert

sched = BlockingScheduler()

# Schedule job_function to be called every two hours
sched.add_job(send_alert,'interval',hours=10)

sched.start()

所以我知道如何显示输出中刮取的内容调用Twilio API,但我不知道如何将经过刮取的输出通过Twilio发送到我的手机。

解决方法

您需要通过添加参数并将要发送的数据传递到send_alert()函数,并将body的硬编码值替换为传入的值