-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting-requests.py
86 lines (57 loc) · 1.8 KB
/
testing-requests.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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import logging
from time import sleep
from scrapeops_python_requests.scrapeops_requests import ScrapeOpsRequests
import logging
log = logging.getLogger()
logging.basicConfig()
## Install ScrapeOps
scrapeops_logger = ScrapeOpsRequests(
scrapeops_api_key= 'YOUR-API-KEY-HERE',
spider_name='ScrapeOps',
job_name='Test'
)
############ NORMAL REQUESTS TESTING ################
requests = scrapeops_logger.RequestsWrapper()
log.warning("*********** test single warning ***********")
## Testing GET requests
urls = [
'https://quotes.toscrape.com/page/asd/',
'https://quotes.toscrape.com/page/asdasd/',
'http://quotes.toscrape.com/page/1/',
'http://quotes.toscrape.com/page/2/',
'http://quotes.toscrape.com/page/3/',
'http://quotes.toscrape.com/page/4/',
'http://quotes.toscrape.com/page/5/',
]
for url in urls:
## Warning/errors testing
log.warning("*********** test multiple warning ***********")
## Testing an error
# division_by_zero = 1 / 0
## Testing standard requests
getResponse1 = requests.get(url)
## Testing just straight request and GET
getResponse2 = requests.request('GET',url)
item = {'test': 'hello'}
## Log the item with Scrapeops
scrapeops_logger.item_scraped(
response=getResponse2,
item=item
)
sleep(2)
# Testing Post Requests
postUrls = [
'https://eoqry8epqmc2rmi.m.pipedream.net',
]
for postUrl in postUrls:
## Testing post requests
postResponse1 = requests.post(postUrl)
## Testing just straight request and POST
postResponse2 = requests.request('POST',postUrl)
item = {'test': 'hello'}
## Log the item with Scrapeops
scrapeops_logger.item_scraped(
response=postResponse2,
item=item
)
sleep(2)