步骤
- 首先找到淘宝登陆界面:
https://login.taobao.com/member/login.jhtml
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/dcf8e32b5c21f4420f90a335410e826b.png)
- 使用selenium + beautiful进行模拟登陆+数据爬取,可以稍微延长等待时间:
from selenium import webdriver
import time
import random
from bs4 import BeautifulSoup
import csv
import re
def main():
tb = webdriver.Chrome()
tb.maximize_window()
tb.get("https://login.taobao.com/member/login.jhtml")
time.sleep(random.choice([1,2]))
tb.find_element_by_name("fm-login-id").send_keys("账号名")
time.sleep(random.choice([1,2]))
tb.find_element_by_name("fm-login-password").send_keys("密码")
time.sleep(random.choice([5,6,7,8]))
tb.find_element_by_xpath("//*[@id='login-form']/div[4]/button").click()
time.sleep(random.choice([2,3,5]))
page_num = 10
for i in range(1,page_num+1):
url = "https://s.taobao.com/search?q={}&s={}".format('口红'