1. # 爬取当当网图书
    2. import requests
    3. from pyquery import PyQuery
    4. import csv
    5. import time
    6. class DDSider(object):
    7. def __init__(self,key):
    8. self.key = key
    9. self.headers = {
    10. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
    11. }
    12. self.base_url = 'http://search.dangdang.com/?key='+key+'&act=input&page_index={}'
    13. # 获取界面内容
    14. def get_pageInfo(self):
    15. num_page = 0
    16. while True:
    17. num_page += 1
    18. page_url = self.base_url.format(num_page)
    19. res = requests.get(page_url,headers=self.headers)
    20. # print(res.content.decode('GBK'))
    21. # 解析
    22. self.parse_pageInfo(res.content.decode('GBK'))
    23. time.sleep(1)
    24. if num_page == 1:
    25. break
    26. def parse_pageInfo(self,html):
    27. doc = PyQuery(html)
    28. book_ul = doc('#component_59 li').items()
    29. for one_li in book_ul:
    30. # print(one_li)
    31. # 图片的链接
    32. if one_li('.pic img').attr('data-original'):
    33. img_url = one_li('.pic img').attr('data-original')
    34. else:
    35. img_url = one_li('.pic img').attr('src')
    36. # 标题
    37. title = one_li('.name a').attr('title')
    38. # 价格
    39. price = one_li('.price .search_now_price').text()
    40. # 获取评价数
    41. comments = one_li('.search_star_line .search_comment_num').text()
    42. #search_star_black
    43. # stars = one_li('.search_star_black span').attr('style').split(':')[-1].strip('%;')
    44. stars = float(one_li('.search_star_black span').attr('style').split(':')[-1].strip('%;'))/20
    45. # print(stars)
    46. if __name__ == "__main__":
    47. dd = DDSider('python')
    48. dd.get_pageInfo()
    1. 5.0
    2. 4.5
    3. 4.5
    4. 4.5
    5. 4.5
    6. 4.5
    7. 4.5
    8. 5.0
    9. 4.5
    10. 4.5
    11. 5.0
    12. 4.5
    13. 5.0
    14. 3.0
    15. 4.5
    16. 4.5
    17. 5.0
    18. 5.0
    19. 5.0
    20. 4.5
    21. 5.0
    22. 4.5
    23. 4.5
    24. 4.5
    25. 4.5
    26. 0.0
    27. 4.5
    28. 4.5
    29. 4.5
    30. 4.0
    31. 4.5
    32. 5.0
    33. 4.0
    34. 5.0
    35. 4.5
    36. 4.5
    37. 4.5
    38. 5.0
    39. 3.0
    40. 5.0
    41. 5.0
    42. 5.0
    43. 5.0
    44. 4.5
    45. 4.5
    46. 0.0
    47. 5.0
    48. 5.0
    49. 4.5
    50. 5.0
    51. 4.0
    52. 5.0
    53. 4.5
    54. 5.0
    55. 4.5
    56. 0.5
    57. 4.5
    58. 4.5
    59. 4.0
    60. 5.0
    import time
    import requests
    import json
    # 时间戳: 1970-01-01 00:00:00 到当前时间的的秒数(10位数)或者是毫秒数(13位)
    # timestamp = 1559223244110
    # timearray = time.localtime(float(timestamp/1000))
    # tt = time.strftime('%Y--%m--%d %H:%M:%S',timearray)
    # print(tt)
    
    # 把当前时间转成时间戳的格式
    
    # timestamp = int(time.time())*1000
    # timearray = time.localtime(float(timestamp/1000))
    # tt = time.strftime('%Y--%m--%d %H:%M:%S',timearray)
    # print(tt)
    # 动态界面的爬取
    base_url = 'https://careers.tencent.com/tencentcareer/api/post/Query?timestamp={}&keyword=Python&pageIndex=1&pageSize=10&language=zh-cn&area=cn'
    
    timestamp = int(time.time())*1000
    headers = {
                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
            }
    url = base_url.format(timestamp)
    print(url)
    
    res = requests.get(url=url,headers=headers)
    # print(res.content.decode('utf-8'))
    
    # 将数据转化成Python对象
    conntent_dict = json.loads(res.content.decode('utf-8'))
    
    Data_dict = conntent_dict['Data']
    # posts_list 里面存的就是我们想要的数据
    posts_list = Data_dict['Posts']
    
    # 拿到每一条数据
    for value_dict in posts_list:
    
        RecruitPostName = value_dict['RecruitPostName']
        print(RecruitPostName)
        LastUpdateTime = value_dict['LastUpdateTime']
        print(LastUpdateTime)
    
    https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1559224906000&keyword=Python&pageIndex=1&pageSize=10&language=zh-cn&area=cn
    25923-监控系统开发工程师(Python)(深圳)
    2019年05月30日
    31504-AI机器人后台开发工程师(python)
    2019年05月29日
    CSIG16-python高级研发工程师
    2019年05月25日
    TME-腾讯音乐python开发工程师
    2019年05月17日
    25923-Python高级工程师(上海)
    2019年04月19日
    25923-Python高级工程师(深圳)
    2019年04月19日
    25923-数据分析平台开发工程师(Python)(深圳)
    2019年03月21日
    PCG04-安全测试专家(后台服务/客户端)
    2019年05月30日
    30359-大数据高级开发工程师(深圳)
    2019年05月30日
    31504-腾讯云监控高级运维工程师
    2019年05月30日