国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

網(wǎng)頁(yè)爬蟲(chóng) - Python3.6 下的爬蟲(chóng)總是重復(fù)爬第一頁(yè)的內(nèi)容

瀏覽:145日期:2022-06-30 17:08:03

問(wèn)題描述

問(wèn)題如題:改成while,試了很多,然沒(méi)有效果,請(qǐng)教大家

# coding:utf-8# from lxml import etreeimport requests,lxml.html,osclass MyError(Exception): def __init__(self, value):self.value = value def __str__(self):return repr(self.value) def get_lawyers_info(url): r = requests.get(url) html = lxml.html.fromstring(r.content) # phones = html.xpath(’//span[@class='law-tel']’) phones = html.xpath(’//span[@class='phone pull-right']’) # names = html.xpath(’//p[@class='fl']/p/a’) names = html.xpath(’//h4[@class='text-center']’) if(len(phones) == len(names)):list(zip(names,phones))phone_infos = [(names[i].text, phones[i].text_content()) for i in range(len(names))] else:error = 'Lawyers amount are not equal to the amount of phone_nums: '+urlraise MyError(error) phone_infos_list = [] for phone_info in phone_infos:if(phone_info[0] == ''): info = '沒(méi)留姓名'+': '+phone_info[1]+'rn'else: info = phone_info[0]+': '+phone_info[1]+'rn'print (info)phone_infos_list.append(info) return phone_infos_listdir_path = os.path.abspath(os.path.dirname(__file__))print (dir_path)file_path = os.path.join(dir_path,'lawyers_info.txt')print (file_path)if os.path.exists(file_path): os.remove(file_path)with open('lawyers_info.txt','ab') as file: for i in range(1000):url = 'http://www.xxxx.com/cooperative_merchants?searchText=&industry=100&provinceId=19&cityId=0&areaId=0&page='+str(i+1)# r = requests.get(url)# html = lxml.html.fromstring(r.content)# phones = html.xpath(’//span[@class='phone pull-right']’)# names = html.xpath(’//h4[@class='text-center']’) # if phones or names:info = get_lawyers_info(url)for each in info: file.write(each.encode('gbk'))

問(wèn)題解答

回答1:

# coding: utf-8import requestsfrom pyquery import PyQuery as Qurl = ’http://www.51myd.com/cooperative_merchants?industry=100&provinceId=19&cityId=0&areaId=0&page=’with open(’lawyers_info.txt’, ’ab’) as f: for i in range(1, 5):r = requests.get(’{}{}’.format(url, i))usernames = Q(r.text).find(’.username’).text().split()phones = Q(r.text).find(’.phone’).text().split()print zip(usernames, phones)

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 日本高清色本免费现在观看 | 精品欧美激情在线看 | 亚洲精品乱无伦码 | 日韩美女毛片 | 草草影院www色极品欧美 | 日本亚洲欧美在线 | 在线免费黄色网址 | 日本一区视频在线观看 | 一区二区三区免费视频播放器 | 中文字幕一区二区三 | 国内亚州视频在线观看 | 99在线在线视频免费视频观看 | 亚洲一区二区三区高清视频 | 精品久久网 | 怡红院在线a男人的天堂 | 国产区二区 | 国产三片高清在线观看 | 免费观看性欧美毛片 | 97久久曰曰久久久 | 日本三级全黄三级a | 免费中文字幕 | 真人毛片免费全部播放完整 | a级毛片在线视频免费观看 a级免费 | 成人毛片免费网站 | 男人的亚洲天堂 | 国产四区| 亚洲国产一区二区三区综合片 | 视频在线一区 | 精品国产v | 国产日产亚洲系列首页 | 另类毛片 | 国产农村乱 | 夜色www | 日韩三级一区 | 日本欧美做爰全免费的视频 | 日本免费高清一区 | 中文国产成人精品久久水 | 国产手机看片 | 精品日韩欧美一区二区三区 | 免费三级网站 | 国产精品自在自线亚洲 |