-
Notifications
You must be signed in to change notification settings - Fork 1
/
XingScraper.py
44 lines (33 loc) · 1.31 KB
/
XingScraper.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
import requests
from lxml import html
USERNAME = "<USERNAME>"
PASSWORD = "<PASSWORD>"
LOGIN_URL = "https://login.xing.com//login"
URL = "https://www.xing.com/search/members?_=1535121078113&advanced_form=true&keywords=Krankenschwester&page=2&province=Hessen§ion=members"
def main():
session_requests = requests.session()
# Get login csrf token
result = session_requests.get(LOGIN_URL)
tree = html.fromstring(result.text)
authenticity_token = list(set(tree.xpath("//input[@name='authenticity_token']/@value")))[0]
# Create payload
payload = {
"login_form[username]": USERNAME,
"login_form[password]": PASSWORD,
# "authenticity_token": authenticity_token
"login_form[token_param]":authenticity_token
}
# Perform login
result = session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
# print(result.content)
# Scrape url
result = session_requests.get(URL, headers = dict(referer = URL))
tree = html.fromstring(result.content)
print(result.content)
text_file = open("Output2.txt", "w")
text_file.write(result.content)
text_file.close()
images = tree.xpath("//img[@class='user-photo']/text()")
print(images)
if __name__ == '__main__':
main()