res_d_l =[{'contents':d.contents,'href':d.attrs['href']} for d in rd] 泛型
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# from selenium.webdriver.firefox.options import Options
import time
from time import sleep
import math
import random
import sys
import threading
from random import choice
# import urllib.parse
from bs4 import BeautifulSoup ua_list = []
with open('mobile_ua.txt', 'r', encoding='utf-8') as uafile:
for i in uafile:
if i.find('Mozilla') > -1:
ua_list.append(i.replace('\n', '').strip()) ua_list_len_ = len(ua_list) - 1 def close_alert(browser, attitude='accept'):
# js='alert(window.alert=function(str){return;}'
# browser.execute_script(js) # js= 'window.alert = function(str){return ;}'
# browser.execute_script(js)
return # mobile_emulation = {
# "deviceMetrics": {"width": 360, "height": 640, "pixelRatio": 3.0},
# "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"}
ua_list_index = random.randint(0, ua_list_len_)
# mobile_emulation = {
# "deviceMetrics": {"width": 360, "height": 640, "pixelRatio": 3.0}}
#
# mobile_emulation['userAgent'] = choice(ua_list)
# chrome_options = Options()
# chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
# browser = webdriver.Chrome(chrome_options=chrome_options)
browser = webdriver.Chrome()
s_wd = '长尾词'
url_seed = 'https://m.baidu.com/s?word=s_wd' url_seed = url_seed.replace('s_wd', s_wd)
print(url_seed)
browser.get(url_seed) rd = BeautifulSoup(browser.page_source, 'html.parser').find_all('a', class_='rw-item')
res_d_l = [{'contents': d.contents, 'href': d.attrs['href']} for d in rd]
browser.quit()
d = 3
res_d_l =[{'contents':d.contents,'href':d.attrs['href']} for d in rd] 泛型的更多相关文章
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- window.location.href = window.location.href 跳转无反应 a 超链接 onclick 点击跳转无反应
错误写法 , 主要是在 href="#"这里 <a href="#" id="send" onclick="return b ...
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
location.href 和 window.location.href 区别: 1.location.href 可以直接跳转其他地址(不属于本项目) 也可以跳转本项目中的 2.window.loca ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别(跳出iframe方法)
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法
关于js中"window.location.href"."location.href"."parent.location.href".&qu ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href用法
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- window.location.href = window.location.href window.location.reload()
w 0-会议预订提交了预订日期,预订成功后默认显示仅显示当前日期的新页面若显示预定日的信息,则可以对预定日存入cookie: http://stackoverflow.com/questions/24 ...
- "window.location.href"、"location.href"是本页面跳转
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- a href=#与 a href=javascript:void(0) 的区别
a href="#"> 点击链接后,页面会向上滚到页首,# 默认锚点为 #TOP <a href="javascript:void(0)" onCl ...
随机推荐
- Django 动态建表
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Random_lee # -*- coding: utf-8 -*- from django ...
- 使用github中py12306抢票系得
首先需要安装最新的python:安装步骤见:https://www.cnblogs.com/weven/p/7252917.html 其次下载python源码: 链接:https://pan.baid ...
- python-----定制群发微信消息
如何使用表格中的信息群发微信消息? 如何读取csv? → 使用内置模块csv 如何按对应信息发送到微信?→ 使用第三方库wxpy 以下代码素材自取:链接:https://pan.baidu.co ...
- 【HDU 6000】Wash(贪心)
Problem Description Mr.Panda is about to engage in his favourite activity doing laundry! He's brough ...
- Java基础学习总结(93)——Java编码规范之代码性能及惯例
1.避免使用包装类构造函数 按照SUN公司的说明,使用自动装箱或静态工厂方法比使用new一个对象快3到4倍,该规则可以用在valueOf或其它静态工厂的调用中(如:Short.Integer, Lon ...
- reactNative 介绍
React Native (简称RN)是Facebook于2015年4月开源的跨平台移动应用开发框架,是Facebook早先开源的UI框架 React 在原生移动应用平台的衍生产物,目前支持iOS和安 ...
- XV6第一个进程
第一个进程 本章通过第一个进程的创建来解释 xv6 是如何开始运行的,让我们得以一窥 xv6 提供的各个抽象是如何实现和交互的.xv6 尽量复用了普通操作的代码来建立第一个进程,避免单独为其撰写代码. ...
- 【BZOJ2038】小Z的袜子(莫队)
题意: 给定n个数a1, a2…… an与m个询问(L,R).对于每个询问,从aL, aL+1…… aR这R-L+1个数中随机取出两个数,求这两个数相同的概率. 数据范围:1<=n,m,ai&l ...
- ***js常用方法汇总(源自实际中的项目)
Q: 400-819-0717转8888,取后四位分机号 A: 方法一: alert("abcdefg".slice(-4));方法二:var str= "abcdefg ...
- python学习之 - XML
xml模块定义:实现不同语言或程序之间进行数据交换的协议.格式如下:通过<>节点来区别数据结构如:<load-on-startup(这个是标签) test="value&q ...