Hi,
Ik heb een script geschreven die bepaalde secties van een website in de gaten houdt en bij een wijziging een melding maakt.
Ik loop echter vast in het stukje x-path.
Hieronder het gedeelte waar ik vast loop:
En hierbij de volledige code:
Ik ben blind gestaard inmiddels. BTW Feel free to use it voor jezelf.
Overigens gebruik ik nu Marktplaats voor demo doeleinden.
Ik heb een script geschreven die bepaalde secties van een website in de gaten houdt en bij een wijziging een melding maakt.
Ik loop echter vast in het stukje x-path.
Hieronder het gedeelte waar ik vast loop:
code:
1
2
3
4
5
| # Set the target URL and request the site and look for the ID tag
source = requests.get(url).text
soup = bs4.BeautifulSoup(source,'html.parser')
#event_string = str(soup.find('div', id='content'))
event_string = str(soup.find_all("div",{"class": "mp-Nav-breadcrumb-item"}, id='content')) |
En hierbij de volledige code:
code:
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| import http.client, urllib
import smtplib
import bs4
import requests
import time
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
titel = "Marktplaats - iPhone"
url = "https://www.marktplaats.nl/q/iphone/#postcode:XXXX|searchInTitleAndDescription:true"
try:
conn = http.client.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.parse.urlencode({ "token":
"jkww2erh", "user":
"x8d1vsixo",
"sound": "cosmic",
"title": titel + " - Change Detection Gestart.", "message": "Initieel bericht, monitoring gestart.",
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
except Exception as e:
print (titel + " - Initiele Pushover kon niet worden verzonden, zijn de instellingen wel goed?")
print(e)
exit()
# Set the target URL and request the site and look for the ID tag
source = requests.get(url).text
soup = bs4.BeautifulSoup(source,'html.parser')
#event_string = str(soup.find('div', id='content'))
event_string = str(soup.find_all("div",{"class": "mp-Nav-breadcrumb-item"}, id='content'))
# Start a loop where we check the site again
while True:
time.sleep(30)
source = requests.get(url).text
soup = bs4.BeautifulSoup(source,'html.parser')
event_string_new = str(soup.find_all("div",{"class": "mp-Nav-breadcrumb-item"}, id='content'))
# If the html of the form has changed trigger the Pushover!
if event_string!=event_string_new:
try:
# SEND THE PUSHOVER!!!!
conn = http.client.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.parse.urlencode({ "token":
"kww2erh", "user":
"d1vsixo",
"sound": "cosmic",
"title": titel + " - Change Detected", "message": "De website lijkt gewijzigd, notificatie actief.",
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
event_string = event_string_new
except:
print (titel + " - Something went wrong sending the Pushover when a changed was discovered...") |
Ik ben blind gestaard inmiddels. BTW Feel free to use it voor jezelf.
Overigens gebruik ik nu Marktplaats voor demo doeleinden.