Home > other >  Python is how to solve the crawl steam market price is not all of China's currency
Python is how to solve the crawl steam market price is not all of China's currency

Time:12-11

The import requests
The import CSV
The import re
Import the random
The import codecs
The from bs4 import BeautifulSoup
The import time
Sleeptime=1
List_name=[]
List_buff_price=[]
List_steam_price=[]
List_fa=[];
User_agent=[
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10 _6_8; En - us) AppleWebKit/534.50 (KHTML, like Gecko) Version 5.1/Safari/534.50 ",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; En - us) AppleWebKit/534.50 (KHTML, like Gecko) Version 5.1/Safari/534.50 ",
"Mozilla/5.0 (Windows NT 10.0; WOW64. The rv: 38.0) Gecko/20100101 Firefox/38.0 ",
"Mozilla/5.0 (Windows NT 10.0; WOW64. Trident/7.0; . NET4.0 C; . NET4.0 E; The.net CLR 2.0.50727; The.net CLR 3.0.30729; The.net CLR 3.5.30729; InfoPath. 3; The rv: 11.0) like Gecko,
""Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0), "
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0), "
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0), "
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1), "
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; The rv: Gecko/20100101 Firefox 2.0.1)/4.0.1,
""Mozilla/5.0 (Windows NT 6.1; The rv: Gecko/20100101 Firefox 2.0.1)/4.0.1,
""Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; En) Presto/2.8.131 Version/11.11 ",
"Opera/9.80 (Windows NT 6.1; U; En) Presto/2.8.131 Version/11.11 ",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10 _7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11 ",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0), "
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0), "
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1), "
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World),
""Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2. MetaSr 1.0 X; SE 2. MetaSr 1.0 X; The.net CLR 2.0.50727; SE 2 X MetaSr 1.0), "
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360 se),
""Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser),
""Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1), "
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4 _3_3 like Mac OS X; En - us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version 5.0.2/Mobile/8 j2 Safari/6533.18.5,
""Mozilla/5.0 (iPod; U; CPU iPhone OS 4 _3_3 like Mac OS X; En - us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version 5.0.2/Mobile/8 j2 Safari/6533.18.5,
""Mozilla/5.0 (the device; U; CPU OS 4 _3_3 like Mac OS X; En - us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version 5.0.2/Mobile/8 j2 Safari/6533.18.5,
""Mozilla/5.0 (Linux; U; Android 2.3.7. En - us; The Nexus One Build/FRF 91) AppleWebKit/533.1 (KHTML, like Gecko) Version 4.0/533.1/Mobile Safari, "
"MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7. Useful - cn; MB200 Build/GRJ22; CyanogenMod 7) AppleWebKit/533.1 (KHTML, like Gecko) Version 4.0/533.1/Mobile Safari, "
"Opera/9.80 (Android 2.3.4; Linux; Opera.mobi/build - 1107180945; U; En - GB) Presto/2.8.149 Version/11.10 ",
"Mozilla/5.0 (Linux; U; The Android 3.0. En - us; The Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version 4.0/Safari/534.13 ",
"Mozilla/5.0 (BlackBerry; U; The BlackBerry 9800; En) AppleWebKit/534.1 + (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1 + ",
"Mozilla/5.0 (HP - tablet; Linux; HpwOS/3.0.0; U; En - US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/Safari 233.70/534.6 the TouchPad/1.0 ",
"Mozilla/5.0 (SymbianOS/9.4; Series60/5.0/20.0.019 NokiaN97-1; Profile/Configuration/MIDP 2.1 CLDC 1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124,
""Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC. Titan),
""
UCWEB7.0.2.37/28/999","NOKIA5700/UCWEB7.0.2.37/28/999,"
"Openwave/UCWEB7.0.2.37/28/999,"
"Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999 ",
]
# headers={' the user-agent: the random choice (user_agent)}

Def get_steam_page (url) :
Headers={
'cookies' :'
'the user-agent: the random choice (user_agent),
'the Accept - Language' : 'en - US, en; Q=0.5 ',
'Connection' : 'keep alive -'
}
Res=requests. Get (url)
Soup=BeautifulSoup (res) text, ". The HTML parser ")
Return soup
Def get_buff_page (url) :
Headers={
'cookies' :'
'the user-agent: the random choice (user_agent),
'the Accept - Language' : 'en - US, en; Q=0.5 ',
'Connection' : 'keep alive -'
}
Res=requests. Get (url)
Soup=BeautifulSoup (res) text, ". The HTML parser ")
Return soup
Def steam_page (soup) :
The grid=soup. The find (' div ', attrs={" id ":" BG_bottom "})
Goods=grid. The find (' div ', attrs={" id ":" searchResultsRows "})
Price_steam=goods. Find (" span ", attrs={" calss ", "market_listing_price market_listing_price_with_fee"})
# print (price_steam)
Print (price_steam. Get_text (.) strip ())
List_steam_price. Append (price_steam. Get_text () strip ())
Def parse_page (soup) :
# return_list=[]
# large container
The grid=soup. The find (' div ', attrs={" class ":" market - the list "})
If the grid:
# name
Goods_name=grid. The find (' div ', attrs={" class ":" the detail - cont "})
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related