blob: b9fc54e1109b28e1c318f8b3fd1ee7200ae205eb (
plain)
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
|
Description: Add Header User-agent and Accept
Author: Jörg Frings-Fürst <debian@jff-webhosting.net>
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=862004
Forwarded: https://github.com/Debianguru/MailWebsiteChanges/issues/11
Last-Update: 2017-05-07
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: trunk/mwc.py
===================================================================
--- trunk.orig/mwc.py
+++ trunk/mwc.py
@@ -68,6 +68,8 @@ def parseSite(site):
contenttype = site.get('type', 'html')
contentregex = site.get('contentregex', '')
titleregex = site.get('titleregex', '')
+ UserAgent = site.get('User-agent', '')
+ Accept = site.get('Accept', '')
enc = site.get('encoding', defaultEncoding)
contentxpath = site.get('contentxpath', '')
@@ -86,7 +88,12 @@ def parseSite(site):
file = process.stdout
else:
# open website
- file = urllib.request.urlopen(uri)
+ req = urllib.request.Request(uri)
+ if UserAgent != '':
+ req.add_header('User-agent', UserAgent)
+ if Accept != '':
+ req.add_header('Accept', Accept)
+ file = urllib.request.urlopen(req)
if contenttype == 'text' or (contentxpath == '' and titlexpath == ''):
|