Q
Q
question 12017-02-05 00:30:42
Python
question 1, 2017-02-05 00:30:42

Trouble with python parsing?

I decided to parse aliexpress. There was a problem
Code:

import requests
from bs4 import BeautifulSoup
r = requests.get('https://ru.aliexpress.com/af/flash%252B32%252Bgb/9.html?isAffiliate=y&initiative_id=AS_20170204114829&site=rus&SearchText=flash+32+gb&tc=af&CatId=202001176')
soup = BeautifulSoup(r.text, 'lxml')
pages = soup.find('div', class_='ui-pagination').find_all('a', class_='ui-pagination-prev')[-1]

What do I get:
>>> pages
<a class="ui-pagination-prev" href="//ru.aliexpress.com/af/flash%252B32%252Bgb/8.html?isAffiliate=y&amp;initiative_id=AS_20170204114829&amp;site=rus&amp;SearchText=flash+32+gb&amp;tc=af&amp;CatId=202001176">Предыдущий</a>

But I must receive
<a class="page-next ui-pagination-next" href="//ru.aliexpress.com/af/flash%252B32%252Bgb/10.html?isAffiliate=y&initiative_id=AS_20170204114829&site=rus&SearchText=flash+32+gb&tc=af&CatId=202001176">Следующий</a>

But there are different classes and I don't quite understand how to implement it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Dergachov, 2017-02-05
@JsDev

soup.find('div', class_='ui-pagination').find_all('a', class_='page-next ui-pagination-next')[-1]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question