-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawler.py
27 lines (21 loc) · 1 KB
/
crawler.py
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
import requests
import json
from bs4 import BeautifulSoup
TWITTER_BASE_URL = 'https://twitter.com'
def crawl():
links = []
with open("configuration.json") as configurationFile:
configurations = json.loads(configurationFile.read())
for url in configurations['sources']:
request = requests.get(url)
soup = BeautifulSoup(request.content, 'html5lib')
tweets = soup.findAll("div", {"class": "tweet"})
for tweet in tweets:
tweetContent = tweet.findAll("div", {"class": "content"})[0]
#tweetTime = tweetContent.findAll("small", {"class": "time"})[0].a.get('title')
tweetPost = tweetContent.findAll("p", {"class": "TweetTextSize"})[0]
tweetText = tweetPost.get_text()
tweetTextLowerCase = tweetText.lower()
if any(searchTerm in tweetTextLowerCase for searchTerm in configurations['search_terms']):
links.append(TWITTER_BASE_URL + tweet['data-permalink-path'])
return links