xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡介

利用selenium編寫的python網絡爬蟲-淘寶商品信息并保存到mysql數據庫。包括寶貝的詳細信息

資源截圖

代碼片段和文件信息

from?selenium?import?webdriver
from?selenium.webdriver.common.by?import?By
from?selenium.webdriver.support.ui?import?WebDriverWait
from?selenium.webdriver.support?import?expected_conditions?as?EC
from?pyquery?import?PyQuery?as?pq
from?Tbmeishi.config?import?*
import?MySQLdb

#?browser?=?webdriver.Chrome()???使用chrome來運行,會跳出界面
browser?=?webdriver.PhantomJS(service_args=[‘--load-images=false‘?‘--disk-cache=true‘])
wait?=?WebDriverWait(browser?10)
#?設置phantomjs的界面大小
browser.set_window_size(1400?900)


def?search():
????print(‘正在搜索‘)
????browser.get(‘https://www.taobao.com‘)
????#?判斷加載是否成功
????#?輸入框選擇器
????input?=?wait.until(
????????????EC.presence_of_element_located((By.CSS_SELECTOR?‘#q‘))
????)
????#?點擊事件J_TSearchForm?>?div.search-button?>?button
????submit?=?wait.until(
????????????EC.element_to_be_clickable((By.CSS_SELECTOR?‘#J_TSearchForm?>?div.search-button?>?button‘)))
????#?輸入搜索內容KEYWORD
????input.send_keys(KEYWORD)
????#?點擊搜索
????submit.click()
????#?網頁等待
????total?=?wait.until(
????????????EC.presence_of_element_located((By.CSS_SELECTOR?“#mainsrp-pager?>?div?>?div?>?div?>?div.total“)))
????get_products()
????return?total.text


def?next_page(page_number):
????print(‘正在翻頁%d‘?%?page_number)
????try:
????????#?頁碼的數據框選擇器
????????input?=?wait.until(
????????????????EC.presence_of_element_located((By.CSS_SELECTOR?‘#mainsrp-pager?>?div?>?div?>?div?>?div.form?>?input‘))
????????)
????????#?確定按鈕
????????submit?=?wait.until(
????????????????EC.element_to_be_clickable(
????????????????????????(By.CSS_SELECTOR?‘#mainsrp-pager?>?div?>?div?>?div?>?div.form?>?span.btn.J_Submit‘)))
????????#?清除下面的頁碼
????????input.clear()
????????#?寫入當前頁的下一頁
????????input.send_keys(page_number)
????????#?點擊確定按鈕
????????submit.click()
????????wait.until(EC.text_to_be_present_in_element(
????????????????(By.CSS_SELECTOR?‘#mainsrp-pager?>?div?>?div?>?div?>?ul?>?li.item.active?>?span‘)?str(page_number)))
????????get_products()
????except?TimeoutError:
????????next_page

評論

共有 條評論