python脚本 - 刮取数据但不循环并返回所有结果

时间:2017-05-28 16:55:10

标签: python web-scraping beautifulsoup

我是python的新手,需要一些帮助 请参阅下面的py脚本,它会返回一个条目的信息,但我希望它能够恢复该URL上出现的所有项目,包括未显示的页面,需要更改下面的内容才能做到这一点?

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as Soup

my_url = 'https://www.newegg.com/global/uk/Product/ProductList.aspx?
Submit=ENE&DEPA=0&Order=BESTMATCH&Description=graphics+card&N=-1&isNodeId=1'

uClient=uReq(my_url)
page_html = uClient.read()
uClient.close()

page_soup = Soup(page_html, 'html.parser')
containers = page_soup.findAll('div',{'class':'item-container'})
for container in containers: 
    brand = container.div.div.a.img['title']

    title_container = container.findAll('a',{'class':'item-title'})
    product_name = title_container [0].text

    price_container = container.findAll('li',{'class':'price-current'})
    Price = price_container[0].text.strip()

    print("brand: " + brand)
    print("product_name: " + product_name)
    print("Price: + " + Price)

0 个答案:

没有答案