爬1688商品---(测试版)

半成品.

from DrissionPage import ChromiumPage
import time
from selenium import webdriver
url='https://p4psearch.1688.com/hamlet.html?scene=6&cosite=baidujj_pz&location=re&trackid=885662561117990122602'

page=ChromiumPage()

page.get(url)


def key_wof():
    index1=0
   
    for index in range(1,10):
        index1+=1
        print(f'正在爬取第{index1}页')
        size=0
        # 初始0
        height=200
        # 初始高度
        if(index1>10):
            break
        else:
            for inex_list in page.eles('.offer-item'):
                price1=inex_list.ele('.symbol').inner_html
                prices2=inex_list.ele('.number n-b').inner_html
                price3=inex_list.ele('.number n-s').inner_html
                price=price1+prices2+price3
                # 获取商品价格
                ab=810703814121
                date_base=f'https://detail.1688.com/offer/{ab}.html'
                # 这里是demo链接,具体链接根据实际商品来...

                # 待处理的url
                dit={
                    '商品图片':inex_list.ele('.offer-img').attr('src'),
                    '商品链接':date_base,
                    '商品名称':inex_list.ele('.offer-title two-row').inner_html,
                    '商品价格':price,
                    '商品销量':inex_list.ele('.solt').inner_html,
                    '商品来源商家':inex_list.ele('.name').inner_html,
                    '商品商家状态':inex_list.ele('.ww-link ww-inline ww-online').attr('title'),
                    '商品商家链接':inex_list.ele('.ww-link ww-inline ww-online').attr('href')
                }
                
                # time.sleep(2)
                # 给停留一段时间,让页面数据,进行爬取,--为了防止被验证码动态检测
                page.scroll.to_location(size+200,height+500)
                time.sleep(0.1)
                page.scroll.to_location(size+600,height+700)
                time.sleep(0.2)
                page.scroll.to_location(size+800,height+900)
                time.sleep(0.1)
                page.scroll.to_location(size+990,height+1100)
                page.scroll.to_location(size+1200,height+1300)
                print(dit)
def _key():

    over_list=input('请输入商品名称:')  # 未做处理==========================
    if(over_list==''):
        print('输入为空,请重新输入!')
    else:
        key_wof()
    
_key()

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Selenium是一个用于Web应用程序测试的工具,它可以模拟用户操作浏览器来执行各种任务。针对使用Edge浏览器进行虫的需求,需要注意以下几点: 首先,安装Selenium和对应的浏览器驱动。你可以使用conda或pip安装Selenium,根据你的需求选择合适的浏览器驱动。如果使用Edge浏览器,可以在https://msedgewebdriverstorage.z22.web.core.windows.net/ 下载对应版本的64位驱动,并将驱动文件(msedgedriver.exe)放置在Python或Anaconda的Scripts目录中。同时,可能还需要修改Selenium中的webdriver.py文件,将MicrosoftWebDriver.exe修改为msedgedriver.exe。 然后,导入所需的库和模块。在Python脚本中,你需要导入Selenium的webdriver模块以及其他相关的模块,例如By、Keys和WebDriverWait等。同时,你可能还需要导入time和os模块,以便在虫过程中进行延时等操作。 接下来,你可以根据需要编写具体的虫代码。根据你的目标网站和具体需求,使用Selenium的相关方法和功能来模拟用户操作浏览器。你可以使用find_element方法来查找网页元素,使用send_keys方法来输入文本,使用click方法来点击按钮等等。通过结合WebDriverWait和expected_conditions等工具,可以实现更精准的等待和判断操作。 最后,运行你的虫代码。根据你选择的开发环境,可以直接运行Python脚本或在Jupyter Notebook中逐行执行代码。在运行过程中,Selenium会自动打开指定的浏览器,并模拟用户操作来执行虫任务。 需要注意的是,取网站的数据时,请遵守相关法律法规和网站的规定,确保你的行为合法合规。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [anaconda selenium使用Edge 虫](https://blog.csdn.net/puspos/article/details/118437785)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [基于Python Selenium在Edge浏览器下商品信息](https://blog.csdn.net/Wanyunshou2018/article/details/121129660)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

金灰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值