日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python selenium下载优缺点_Python下selenium的实战和普通爬虫的对比

發布時間:2025/3/15 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python selenium下载优缺点_Python下selenium的实战和普通爬虫的对比 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

"""普通爬取數據爬蟲,只要有反爬,cookie就不是很穩定。并不利于數據爬取"""

importrequestsimportrefrom lxml importetree

headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3554.0 Safari/537.36","Referer": "https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=",#Cookie需要時常換取

"Cookie": "_ga=GA1.2.1553999204.1538311958; user_trace_token=20180930205504-0cebb367-c4b0-11e8-bb68-5254005c3644;"

"LGUID=20180930205504-0cebbcd1-c4b0-11e8-bb68-5254005c3644; showExpriedIndex=1; showExpriedCompanyHome=1;"

"showExpriedMyPublish=1; index_location_city=%E6%B7%B1%E5%9C%B3; sensorsdata2015jssdkcross=%7B%22distinct_"

"id%22%3A%22166811f974d15e-026ab47692a8d1-181c7151-2073600-166811f974e549%22%2C%22%24device_id%22%3A%2216681"

"1f974d15e-026ab47692a8d1-181c7151-2073600-166811f974e549%22%7D; LG_LOGIN_USER_ID=1d0d39f3227c1f914a3f9c4d95f"

"4816a5c6667141cc1313edac4603b4bd6d789; hasDeliver=6; _gid=GA1.2.2026255269.1540465512; WEBTJ-ID=2018102519420"

"2-166ab0808f9cb-06806b898438ec-181c7151-2073600-166ab0808fb7ef; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=15401"

"21809,1540210602,1540465512,1540467723; LGSID=20181025194505-6ab63d2a-d84b-11e8-8168-5254005c3644; PRE_UTM=m_cf_"

"cpt_baidu_pc; PRE_HOST=www.baidu.com; PRE_SITE=https%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D0%2"

"6rsv_idx%3D1%26tn%3Dbaidu%26wd%3D%25E6%258B%2589%25E5%258B%25BE%25E7%25BD%2591%26rsv_pq%3D8d0dc05a0000aada%26rsv_t%"

"3D4664T41fswButqvfw6ZM6FGWfkWjtwR%252Fmpsskb6hctTVnUHewMo9o1%252BqRGk%26rqlang%3Dcn%26rsv_enter%3D1%26rsv_sug3%3D7%26r"

"sv_sug1%3D8%26rsv_sug7%3D100; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2Flp%2Fhtml%2Fcommon.html%3Futm_source%3Dm_cf_cpt_baidu_pc;"

"_putrc=1D33894D7A6BEB76123F89F2B170EADC; JSESSIONID=ABAAABAAAGFABEF9CEC8B1F38F5075A286961D31667AC5C; login=true; unick=%E6%9D%A"

"8%E7%A6%B9; gate_login_token=b0629019d50bbe97eb829d61be9770ad4b570c1e68e239c68ae16cc71c68c808; _gat=1; Hm_lpvt_4233e74dff0ae5bd0a"

"3d81c6ccf756e6=1540469398; LGRID=20181025201301-5183464a-d84f-11e8-a347-525400f775ce; TG-TRACK-CODE=index_search; SEARCH_ID=06714"

"3e245964eb7af08d8c8d316cd44"}defrequest_list_page():#獲取詳情頁面url

url = "https://www.lagou.com/jobs/positionAjax.json?city=%E6%B7%B1%E5%9C%B3&needAddtionalResult=false"data={"first": "false","pn": 1,"kd": "Python"}for x in range(1, 31):

data["pn"] =x

rep= requests.post(url=url, headers=headers, data=data)#json方法,如果返回來的是json數據,自動轉換為字典

result =rep.json()#json在線解析分析數據格式

positions = result["content"]["positionResult"]["result"]for position inpositions:

positionId= position["positionId"]#找到詳情頁url,并傳遞給解析函數

position_url = "https://www.lagou.com/jobs/{}.html".format(positionId)

parse_position_detail(position_url)break

break

defparse_position_detail(url):#頁面解析

res = requests.get(url, headers=headers)

text=res.text

html=etree.HTML(text)

position_depart= html.xpath("//div[@class='company']/text()")

position_names= html.xpath("//span[@class='name']/text()")

job_requests= html.xpath("//dd[@class='job_request']//span/text()")

salary_span= re.sub(r"[\s/]", "", job_requests[0].strip())

addr_span= re.sub(r"[\s/]", "", job_requests[1].strip())

exper_span= re.sub(r"[\s/]", "", job_requests[2].strip())

education_span= re.sub(r"[\s/]", "", job_requests[3].strip())

full_span= re.sub(r"[\s/]", "", job_requests[4].strip())

desc= "".join(html.xpath("//dd[@class='job_bt']//text()")).strip()print(position_depart, position_names, salary_span, addr_span, exper_span, education_span, full_span, desc)if __name__ == '__main__':

request_list_page()

總結

以上是生活随笔為你收集整理的python selenium下载优缺点_Python下selenium的实战和普通爬虫的对比的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。