使用selenium進行網路爬蟲

2021-09-22 13:55:36 字數 1204 閱讀 5925

from selenium import webdriver

import datetime

import pandas as pd

import time

import difflib

import multiprocessing as mp

import datetime

def string_similar(s1, s2):

return difflib.sequencematcher(none, s1, s2).quick_ratio()

'返回查詢查詢出來的商品與想要查詢的商品的差別'

def p1():

re=list= '將要查詢的貨品輸入'

n=0for j in list[0:600]:

op = webdriver.firefoxoptions()

op.add_argument('-headless')

'設定無頭瀏覽器模式'

d = webdriver.firefox(options=op)

d.implicitly_wait(15.0)

'靜態的等待,就是說頁面還沒重新整理完畢,你找不到你想要找的元素時,會等待15秒'

d.get(''+j+'/storeid:11807901' )

try:

input = d.find_element_by_xpath('//div/ul/ul/li/a').get_attribute('href')

input1 = d.find_element_by_xpath('//li/a/dl/dt').text

input2 = d.find_element_by_xpath('//div/div/label').text

input4 = d.find_element_by_xpath('//li/a/dl/dd/strong[1]').text

try:

input3 = d.find_element_by_xpath('//li[1]/a/dl/dd/span/span').text

except:

input3=''

except:

pass

d.close()

n+=1

print('p1',n)

pd.dataframe(re).to_excel('商品資訊.xlsx')

使用selenium進行對手機知網的爬取

在留校期間,學習了selenium這個強大的python庫,它的使用完全解決了對一些經過js渲染的網頁的解析和爬取,它可以實現人對網頁的基本操作,這樣也 上的反爬有了很有效的解決,雖然單體執行速度是慢了,但是在之後可以把它加入到scrapy框架裡面,然後實現分布式,提高爬去速度的,接下來我講講我是用...

使用selenium爬拉勾網資料

usr bin env python encoding utf 8 description 使用selenium爬拉勾網資料 from selenium import webdriver from selenium.webdriver.support.ui import webdriverwait ...

selenium 爬取拉勾

用到的知識點 用selenium爬取拉勾 from lxml import etree from selenium import webdriver from selenium.webdriver.support import expected conditions as ec from selen...