【问题标题】:how to webscraping use to scrape the data in Inspect elemrnt or view page source如何使用网页抓取来抓取 Inspect 元素中的数据或查看页面源
【发布时间】:2019-04-05 10:52:53
【问题描述】:

我尝试在特定网站上进行网页抓取。但我无法获取标签。我在 Inspect 元素和视图页面源中也看到标签。如何获取标签请您给我建议。

WebScrapy.py

from bs4 import BeautifulSoup
from urllib.request import urlopen
import html5lib
import urllib
import pandas as pd
import xlsxwriter
from docx import Document
from docx.shared import Inches

document = Document()

url = "https://www.newegg.com/Product/ProductList.aspx?Submit=ENE&DEPA=0&Order=BESTMATCH&Description="
Remaining_url="&ignorear=0&N=-1&isNodeId=1"
product_name = 'Seagate 80GB 7200 RPM SATA 3.0Gb/s Internal Hard Drive (IMSourcing) Bare Drive'
p = document.add_paragraph("Product_name " +":"+"  "+product_name)

search_words = {'text': product_name}
search_url = urllib.parse.urlencode(search_words).split("=")[1]
product_url = url + search_url + Remaining_url
content = urlopen(product_url).read()
soup = BeautifulSoup(content, "html5lib")
print(soup.find_all("div", class_="list-wrap"))  

我运行程序它抛出空列表。如何修复它任何人都可以给出任何解决方案。

【问题讨论】:

  • 我们找到了 0 个符合“Seagate 80GB 7200 RPM SATA 3.0Gb/s Internal Hard Drive (IMSourcing) Bare Drive”的项目。
  • 不,我尝试了很多请求来获取此站点中的数据。但是我得到了一些产品详细信息。它会自动启动机器人。所以如何解决它。以及如何请求 solwly 用于抓取数据。

标签: python python-3.x web-scraping python-requests


【解决方案1】:

是的,没错,结果列表是空的。

        <div class="result-message">
         <p class="result-message-title">
          <span class="result-message-error">
           We have found 0 items that match "Seagate 80GB 7200 RPM SATA 3.0Gb/s Internal Hard Drive (IMSourcing) Bare Drive".
          </span>
         </p>
        </div>

您可以使用 sleep() 在 GET 请求之间暂停:

time.sleep(1.5)

【讨论】:

    最近更新 更多