Guest User

Untitled

a guest
Jan 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.06 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import time
  4. from selenium import webdriver
  5.  
  6. def render_page(url):
  7. driver = webdriver.Firefox()
  8. driver.get(url)
  9. time.sleep(10)
  10. r = driver.page_source
  11. #driver.quit()
  12. return r
  13.  
  14. myUrl = 'https://www.newegg.com/Product/ProductList.aspx?Submit=ENE&DEPA=0&Order=BESTMATCH&Description=graphic+cards&N=-1&isNodeId=1'
  15.  
  16. r = render_page(myUrl)
  17.  
  18. soup = BeautifulSoup(r, "html.parser")
  19.  
  20. containers = soup.findAll("div",{"class":"item-container"})
  21. container = containers[0]
  22.  
  23. container
  24.  
  25. div class="item-container ">
  26. <!--product image-->
  27. <a href="https://www.newegg.com/Product/Product.aspx?Item=N82E16814137291&Description=graphic%20cards&cm_re=graphic_cards-_-14-137-291-_-Product" class="item-img">
  28.  
  29.  
  30. <div class="item-badges">
  31.  
  32. </div>
  33.  
  34.  
  35.  
  36. <img src="https://c1.neweggimages.com/NeweggImage/ProductImageCompressAll300/14-137-291-Z01.jpg?ex=2" title="MSI Radeon RX 570 DirectX 12 RX 570 ARMOR MK2 8G OC 8GB 256-Bit GDDR5 PCI Express x16 HDCP Ready CrossFireX Support Video Card" alt="MSI Radeon RX 570 DirectX 12 RX 570 ARMOR MK2 8G OC 8GB 256-Bit GDDR5 PCI Express x16 HDCP Ready CrossFireX Support Video Card" is-retina="true" class="hoverZoomLink" width="240" height="180">
  37. </a>
  38. <div class="item-info">
  39. <!--brand info-->
  40. <div class="item-branding">
  41.  
  42. <a href="https://www.newegg.com/MSI/BrandStore/ID-1312" class="item-brand">
  43.  
  44.  
  45. <img src="//c1.neweggimages.com/Brandimage_70x28//Brand1312.gif" title="MSI" alt="MSI">
  46. </a>
  47.  
  48. <!--rating info-->
  49.  
  50. <a title="Rating + 5" href="https://www.newegg.com/Product/Product.aspx?Item=N82E16814137291&Description=graphic%20cards&SortField=0&SummaryType=0&PageSize=10&SelectedRating=-1&VideoOnlyMark=False&ignorebbr=1&IsFeedbackTab=true#scrollFullInfo" class="item-rating"><i class="rating rating-5"></i><span class="item-rating-num">(51)</span></a>
  51.  
  52. </div>
  53. <!--description info-->
  54. <a href="https://www.newegg.com/Product/Product.aspx?Item=N82E16814137291&Description=graphic%20cards&cm_re=graphic_cards-_-14-137-291-_-Product" class="item-title" title="View Details"><i class="icon-premier icon-premier-xsm"></i>MSI Radeon RX 570 DirectX 12 RX 570 ARMOR MK2 8G OC 8GB 256-Bit GDDR5 PCI Express x16 HDCP Ready CrossFireX Support Video Card</a>
  55. <!--promption info-->
  56. <p class="item-promo"><i class="item-promo-icon"></i>Get 2 Free Games w/ purchase, limited offer</p>
  57. <!--feature-->
  58. <ul class="item-features">
  59. <li><strong>DisplayPort:</strong> 2 x DisplayPort</li>
  60. <li><strong>DVI:</strong> 1 x DL-DVI-D</li>
  61. <li><strong>HDMI:</strong> 2 x HDMI</li>
  62. <li><strong>Card Dimensions (L x H):</strong> 10.63" x 5.12"</li>
  63.  
  64. <li><strong>Model #: </strong>RX 570 ARMOR MK2 8G OC</li>
  65.  
  66.  
  67. <li><strong>Item #: </strong>N82E16814137291</li>
  68.  
  69.  
  70. <li><strong>Return Policy: </strong><a href="https://kb.newegg.com/Article/Index/12/3?id=1167#80" target="_blank" title="Replacement Only Return Policy(New Window)">Replacement Only Return Policy</a></li>
  71.  
  72.  
  73. </ul>
  74. <div class="item-action">
  75. <!--price-->
  76.  
  77.  
  78. <ul class="price has-label-membership ">
  79. <li class="price-was">
  80.  
  81. </li>
  82. <li class="price-map">
  83.  
  84.  
  85. </li>
  86. <li class="price-current">
  87.  
  88. <span class="price-current-label">
  89.  
  90. <a class="membership-info membership-popup" name="membership" style="display: inline" data-neg-popid="MembershipPopup" href="javascript:void(0);" aria-label="Premier Price Explaination"><span class="membership-icon"></span><span style="display: none">|</span></a>
  91. </span>$<strong>189</strong><sup>.99</sup>&nbsp;<a href="https://www.newegg.com/Product/Product.aspx?Item=N82E16814137291&buyingoptions=New&Description=graphic%20cards" class="price-current-num">(10 Offers)</a>
  92. <span class="price-current-range">
  93. <abbr title="to">–</abbr>
  94. </span>
  95.  
  96. </li>
  97. <li class="price-save ">
  98.  
  99. <span class="price-save-endtime price-save-endtime-current"></span>
  100. <span class="price-save-endtime price-save-endtime-another" style="display:none;"></span>
  101.  
  102.  
  103. </li>
  104. <li class="price-note">
  105.  
  106. <span class="price-note-dollar" data-price="$174.99">$174.99</span>
  107. <span class="price-note-label "> after </span>
  108. <span class="price-note-dollar">$15.00</span>
  109. <span class="price-note-label"> rebate card</span>
  110.  
  111.  
  112. </li>
  113. <li class="price-ship">
  114. Free Shipping
  115. </li>
  116. </ul>
  117.  
  118. <!--egg point-->
  119.  
  120. <!--financing-->
  121.  
  122.  
  123. <!--button-->
  124. <div class="item-operate ">
  125. <div class="item-button-area">
  126.  
  127. <button type="button" title="View Details" class="btn btn-mini " onclick="Javascript:Biz.ProductList.Item.add('https://www.newegg.com/Product/Product.aspx?Item=N82E16814137291&Description=graphic%20cards');">View Details <i class="fa fa-caret-right"></i></button>
  128.  
  129.  
  130.  
  131. </div>
  132.  
  133. <!--compare-->
  134. <div class="item-compare-box">
  135. <label class="form-checkbox">
  136. <input id="CompareItem_14-137-291" autocomplete="off" neg-itemnumber="14-137-291" type="checkbox" name="CompareItem" value="CompareItem_14-137-291">
  137. <span class="form-checkbox-title">Compare</span>
  138. </label>
  139. </div>
  140. <script type="text/javascript">
  141. Biz.Product.CompareConfig.compareItems.push("14-137-291");
  142. var itemThumbs = new Object();
  143. itemThumbs.itemNumber = "14-137-291";
  144. itemThumbs.imageUrl = "//c1.neweggimages.com/ProductImageCompressAll35/14-137-291-Z01.jpg";
  145. Biz.Product.CompareConfig.Thumbs.push(itemThumbs);
  146. </script>
  147.  
  148. </div>
  149. </div>
  150. </div>
  151.  
  152. <div class="item-container" data-itemnumber="35-103-060">
  153. <a class="item-img" href="https://www.newegg.com/Product/Product.aspx?Item=35-103-060&cm_sp=SearchSuccess-_-INFOCARD-_-graphic+cards-_-35-103-060-_-1&Description=graphic+cards" onclick="Javascript:s_search_results_clickthrough(this);s_search_results_clickthrough(this);s_search_results_clickthrough(this);s_search_results_clickthrough(this);">
  154. <img alt="Cooler Master SickleFlow 120 - Sleeve Bearing 120mm Blue LED Silent Fan for Computer Cases, CPU Coolers, and Radiators" height="62" is-retina="true" src="https://c1.neweggimages.com/ProductImageCompressAll300/35-103-060-17.jpg?ex=2" title="Cooler Master SickleFlow 120 - Sleeve Bearing 120mm Blue LED Silent Fan for Computer Cases, CPU Coolers, and Radiators" width="83" />
  155. </a>
  156. <div class="item-info">
  157. <div class="item-branding">
  158. <a class="item-rating" href="https://www.newegg.com/Product/Product.aspx?Item=35-103-060&cm_sp=SearchSuccess-_-INFOCARD-_-graphic+cards-_-35-103-060-_-1&Description=graphic+cards&IsFeedbackTab=true#scrollFullInfo" onclick="Javascript:s_search_results_clickthrough(this);s_search_results_clickthrough(this);s_search_results_clickthrough(this);s_search_results_clickthrough(this);"><i class="rating rating-4"></i><span class="item-rating-num">(2476)</span></a>
  159. </div>
  160. <a class="item-title" href="https://www.newegg.com/Product/Product.aspx?Item=35-103-060&cm_sp=SearchSuccess-_-INFOCARD-_-graphic+cards-_-35-103-060-_-1&Description=graphic+cards" onclick="Javascript:s_search_results_clickthrough(this);s_search_results_clickthrough(this);s_search_results_clickthrough(this);s_search_results_clickthrough(this);">
  161. <i class="icon-premier icon-premier-xsm"></i>
  162.  
  163. Cooler Master SickleFlow 120 - Sleeve Bearing 120mm Blue LED Silen...
  164. </a>
  165. </div>
  166.  
  167. import requests
  168. from bs4 import BeautifulSoup
  169.  
  170. url = 'https://www.newegg.com/Product/ProductList.aspx?Submit=ENE&DEPA=0&Order=BESTMATCH&Description=graphic+cards&N=-1&isNodeId=1'
  171.  
  172. r = requests.get(url)
  173. soup = BeautifulSoup(r.content, 'html.parser')
  174.  
  175. for item in soup.select('.is-grid .item-container'):
  176. print(item.select_one('.item-brand img')['title'])
  177.  
  178. MSI
  179. GIGABYTE
  180. ZOTAC
  181. ...
Add Comment
Please, Sign In to add comment