Skip to content

Instantly share code, notes, and snippets.

@solyard
Last active February 23, 2018 17:44
Show Gist options
  • Save solyard/5e93b9e5cab685a8219b08c107ed1ccc to your computer and use it in GitHub Desktop.
Save solyard/5e93b9e5cab685a8219b08c107ed1ccc to your computer and use it in GitHub Desktop.
def parsing_data():
for i in main.urls:
data, data2 = [], []
r = requests.get(i, headers=main.headers)
text = r.text
doc = fromstring(text)
block = doc.cssselect("#tabs-last-pos > div > div > div.table-cell.cell-full.collapse-768")[0]
if 'WEST' in i:
key = 'west'
elif 'PERSEY' in i:
key = 'persey'
elif 'SATURN' in i:
key = 'saturn'
elif 'OST' in i:
key = 'ost'
elif 'MOLODIZGNIY' in i:
key = 'molod'
else:
key = 'admiral_istomin'
print(key + ' parsing done 100%')
for i in range(1, 8):
try:
data.append([q.text_content() for q in block.cssselect("div:nth-child(%d) > span" % i)])
data2.append([q.text_content() for q in block.cssselect("div:nth-child(%d) > strong" % i)])
except Exception as E:
print(E)
main.ships_data[key] = [data, data2]
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment