0
0 комментариев

помогите пожалуйста найти элемент на странице и вывести его

import pprint
import requests
import lxml.etree
import lxml.html
import lxml.cssselect
import re
 
def get_doc(url):
    try:
        req = requests.get(url)
    except Exception:
        print('Error open. __', Exception)
    else:
        html = req.text
        doc = lxml.html.document_fromstring(html)
        return doc
 
for url in ['http://www.ebay.com/itm/DW-PDP-Concept-Pearlescent-White-Maple-Drumset-/121271668104?pt=US_Drums&hash=item1c3c5acd88', 'http://www.ebay.com/itm/LOT-OF-20-DRUM-SET-TUNING-KEYS-DW-TAMA-PEARL-SABIAN-and-OTHER-UNIQUE-KEYS-/291092068092?pt=US_Drums&hash=item43c67076fc']:
    doc = get_doc(url)
    title = doc.xpath('//h1[<a href="/users/11054/idd"><a href="/users/11054/idd">@id</a></a>="itemTitle"]/text()')
    print(title)
 
    try:
        reviewQuantity = doc.xpath('//div[<a href="/users/11054/idd"><a href="/users/11054/idd">@id</a></a>="si-fbMini"]/text()')[0].strip()
    except Exception as e:
        print(e)
        reviewQuantity = 'None'
 
    print(reviewQuantity, end='\n\n')

проблема в том, что title находится и выводится, а reviewQuantity — нет.

вот вывод:
[‘DW/PDP Concept Pearlescent White Maple Drumset’]
list index out of range
None

['LOT OF 20 DRUM SET TUNING KEYS! DW! TAMA! PEARL! SABIAN! and OTHER UNIQUE KEYS!!']
list index out of range
None


Добавить комментарий