下厨房网站图片爬虫
作者:互联网
# -*- coding:utf-8 -*-
import os
import requests
import urllib
from pyquery import PyQuery
import uuid
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome"
"/75.0.3770.142 Safari/537.36"
}
def href_url_download():
# 1.填写要爬取关键词的list.txt
keyword_list = open("list.txt", 'r', encoding='utf-8')
lines = keyword_list.readlines()
keyword_list.close()
for keyword in lines:
keyword = keyword.strip()
print(keyword)
# 2.修改爬取的页数(1,14),默认爬取13页
for pages in range(1, 14):
page = str(pages)
# https://www.xiachufang.com/search/?keyword=华夫饼&cat=1001&page=2
url = "https://www.xiachufang.com/search/?keyword=" + keyword + "&cat=1001&page= " + page
# print(url)
try:
txt = requests.get(url, headers=headers).text
doc = PyQuery(txt)
# print(d
标签:keyword,下厨房,网站,list,爬虫,url,import,txt,page 来源: https://blog.csdn.net/weixin_38185649/article/details/100746880