搜索爬虫对SEO有什么用处 悬赏1元 已结束
def get_search_article(self, keyword, offset=0):
keyword = urllib.request.quote(keyword)
req_url = "https://www.toutiao.com/search_content/?offset={}&format=json&keyword={}&autoload=true&count=20&cur_tab=1&from=search_tab".format(offset,keyword)
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'Connection': 'keep-alive',
'authority': 'www.toutiao.com',
'referer': "https://www.toutiao.com/search/?keyword={}".format(keyword),
'method': 'GET',
'path': "/search_content/?offset={}&format=json&keyword={}&autoload=true&count=20&cur_tab=1&from=search_tab".format(offset,keyword),
'scheme': 'https'
}
self.s.headers.update(headers)
req = self.s.get(req_url, proxies=get_proxy_ip())
time.sleep(random.random() * 2 + 3)
data = json.loads(req.text)
items = data['data']
if data['has_more'] == 1:
self.page = self.page + 1
offset = 20 * self.page
self.parse_data(items)
time.sleep(2)
self.get_search_article(keyword, offset)
else:
self.parse_data(items)
toutiaodb.save(self.search_item_list)
def parse_data(self, items):
for item in items:
try:
type = item['cell_type']
except:
type = 0
if type == 37: #微头条
pass
elif type == 50:
pass
elif type == 66:
pass
elif type == 26: #内容推荐
pass
elif type == 20: #搜索推荐
pass
elif type == 38: #用户
pass
else:
titem = toutiaoitem()
titem.user_id = item['user_id']
try:
titem.source = item['source']
except:
titem.source = item['name']
titem.title = item['title']
titem.source_url = item['article_url']
titem.media_url = item['media_url']
titem.item_id = item['item_id']
titem.abstract = item['abstract']
titem.comments_count = item['comments_count']
titem.behot_time = item['behot_time']
titem.image_url = item['image_url']
titem.image_list = item['image_list']
titem.tag = item['tag']
if 'play_effective_count' in item:
titem.article_genre = 'vedio'
titem.read_count = item['play_effective_count']
else:
titem.article_genre = 'article'
self.search_item_list.append(titem)
这个东西对SEO有什么用,用法是什么呢