Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

python - I'm trying to build a web scraper and can only pull one css element right now where there are 81

I want to pull all 81 elements, but can only do one at a time this way. The page is dynamic so I'll have more than 81 elements going forward. The page also has several sortableTable-numberattributes so I'm trying to avoid using it as beautifulsoup seems to get confused.

rreads1 = soup.select('tr.sortableTable-row:nth-child(2) > td:nth-child(3) > span:nth-child(2)')
rreads = rreads1[0].get_text()
reads.append(rreads)
question from:https://stackoverflow.com/questions/65839384/im-trying-to-build-a-web-scraper-and-can-only-pull-one-css-element-right-now-wh

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As mentioned, improve your question and add a MRP

Based on the provided information you could loop the macthes:

reads = []

for item in soup.select('tr.sortableTable-row:nth-child(2) > td:nth-child(3) > span:nth-child(2)'):
    rreads = item.get_text()
    reads.append(rreads)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...