Last active
August 19, 2020 07:44
-
-
Save Robotto/7ea07838f6c6233325298aa197d3afdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#run with python3 | |
#js scraper code copied from: https://taras.codes/blog/linkedin-organization-follower-count/ ... replaced regex with string.strip | |
import socket | |
from pyquery import PyQuery | |
import string | |
import time | |
print(time.ctime(),"startup!") | |
TCP_IP = '5.79.74.16' #<-insert server IP here. | |
TCP_PORT = 31337 #<-insert available listener port here | |
BUFFER_SIZE = 20 # Normally 1024, but we want fast response | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #make socket reuseable, for debugging (enables you to rerun the program before the socket has timed out) | |
s.bind((TCP_IP, TCP_PORT)) | |
s.listen(1) | |
print('Opening TCP port', TCP_PORT) | |
while True: | |
try: | |
conn, addr = s.accept() | |
print(time.ctime(),'Connection from:', addr) | |
#txString = str(22) | |
pq = PyQuery(url=f'https://www.linkedin.com/pages-extensions/FollowCompany?id=1558812&counter=bottom') | |
widget_text = pq.text() # equivalent of <document.body.innerText> in JS | |
follower_count = int(widget_text.strip(string.ascii_letters)) | |
txString = str(follower_count)+'\r' | |
conn.sendall(txString.encode('utf-8')) | |
print('TX: ', txString) #txString.replace('\r','\r\n') | |
conn.shutdown(socket.SHUT_WR) | |
conn.close() | |
print('Client disconnected.') | |
print('--------------------------') | |
except Exception as e: | |
#print "hmm.. It looks like there was an error: " + str(e) | |
print('Client disconnected... :',str(e)) | |
print('--------------------------') | |
conn.close() | |
#Arduino snippet: | |
# WiFiClient client; | |
# Serial.print("connecting to "); | |
# Serial.println(host); | |
# if (!client.connect(5.79.74.16, 31337)) { | |
# Serial.println("connection failed"); | |
# return; | |
# } | |
# delay(500); | |
# // Read all the lines of the reply from server and print them to Serial | |
# if(client.available()){ | |
# rawRX=client.parseInt(); | |
# Serial.print("linkedin follower count: "); | |
# Serial.println(rawRX); | |
# follow=rawRX; | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment