Simple crawling of foreign exchange data from fx678

# -*- coding: utf-8 -*-

import requests
import pandas as pd
from lxml import etree
import time
from time import sleep
url = 'http://quote.fx678.com/exchange/WH'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}

response=requests.get(url,headers=headers)
sleep(2)
html=etree.HTML(response.text)

names=html.xpath('//td[1]/a/text()')
prices=html.xpath('//td[2]/text()')
prices_change=html.xpath('//td[3]/span/text()')
price_high=html.xpath('//td[5]/text()')
price_low=html.xpath('//td[6]/text()')
price_yestday=html.xpath('//td[7]/text()')

dict={'names':names,'prices':prices,'prices_change':prices_change,'price_high':price_high,'price_low':price_low,'price_yestday':price_yestday}

df=pd.DataFrame(dict)
df
names price_high price_low price_yestday prices prices_change
0 US dollar index 90.91 90.75 90.79 90.90 0.11
1 EURUSD 1.2239 1.2217 1.2233 1.2219 -0.0014
2 GBP USD 1.3997 1.3970 1.3978 1.3971 -0.0007
3 USDJPY 109.06 108.79 108.82 109.03 0.21
4 AUDUSD 0.7606 0.7573 0.7604 0.7577 -0.0027
5 USD CHF 0.9812 0.9783 0.9789 0.9808 0.0019
6 USD CAD 1.2846 1.2821 1.2833 1.2844 0.0011
7 US dollar Hong Kong dollar 7.8486 7.8458 7.8461 7.8477 0.0016
8 USD onshore RMB 6.3082 6.2982 6.3065 6.3061 -0.0004
9 USD Offshore RMB 6.3065 6.2881 6.2967 6.3056 0.0089
10 NZDCAD 0.9137 0.9110 0.9136 0.9113 -0.0023
11 EURNZD 1.7226 1.7179 1.7182 1.7221 0.0039
12 AUDJPY 82.79 82.53 82.74 82.60 -0.14
13 AUDNZD 1.0693 1.0671 1.0681 1.0679 -0.0002
14 AUDCAD 0.9759 0.9726 0.9758 0.9732 -0.0026
15 CHF JPY 111.23 111.02 111.16 111.16 -0.01
16 AUDCHF 0.7450 0.7429 0.7443 0.7431 -0.0012
17 GBP CAD 1.7951 1.7929 1.7937 1.7945 0.0008
18 EUR GBP 0.8753 0.8740 0.8752 0.8746 -0.0006
19 CAD and CHF 0.7647 0.7624 0.7628 0.7636 0.0008
20 Pound sterling 152.46 152.07 152.10 152.32 0.22
21 EURJPY 133.29 133.03 133.11 133.21 0.10
22 EURCHF 1.1990 1.1973 1.1976 1.1985 0.0009
23 NZDJPY 77.51 77.33 77.47 77.35 -0.12
24 GBP CHF 1.3715 1.3673 1.3683 1.3703 0.0020
25 NZDCHF 0.6973 0.6957 0.6969 0.6959 -0.0010
26 Canadian dollar Japanese yen 85.00 84.76 84.79 84.88 0.09
27 GBP AUD 1.8449 1.8377 1.8384 1.8440 0.0056
28 EUR AUD 1.6133 1.6082 1.6088 1.6127 0.0039
29 GBP NZD 1.9697 1.9628 1.9632 1.9691 0.0059
30 EURCAD 1.5699 1.5678 1.5698 1.5694 -0.0004
31 US Dollar Polish Zloty 3.7395 3.7329 3.7334 3.7359 0.0025
32 US Dollar Mexican Peso 18.857 18.795 18.819 18.852 0.033
33 US Dollar Hungarian Forint 275.76 275.29 275.30 275.70 0.40
34 US Dollar Turkish Lira 4.0914 4.0831 4.0861 4.0877 0.0016
35 US Dollar South African Rand 12.372 12.321 12.326 12.368 0.041
36 US Dollar Czech Koruna 23.706 23.666 23.669 23.693 0.024
37 US Dollar Danish Krone 6.0954 6.0850 6.0890 6.0946 0.0056
38 US dollar Norway 7.9197 7.8958 7.9026 7.9188 0.0162
39 dollar ruble 61.987 61.441 61.523 61.656 0.133
40 dollar swedish 8.5209 8.5067 8.5077 8.5208 0.0131
41 USD SGD 1.3254 1.3218 1.3221 1.3251 0.0030
42 NZDUSD 0.7121 0.7092 0.7120 0.7095 -0.0025
43 bitcoin dollar 4153.62 4019.65 4073.00 4081.77 8.77

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324816213&siteId=291194637