小编Kon*_*nov的帖子

响应式图像对齐中心引导3

我使用Bootstrap 3进行目录.当在平板电脑上显示时,产品图像看起来很难看,因为它们的尺寸很小(500x500),浏览器的宽度为767像素.我想把图像放在屏幕的中央,但由于某种原因,我不能.谁将帮助解决问题?

在此输入图像描述

html css image alignment twitter-bootstrap

417
推荐指数
6
解决办法
82万
查看次数

Flask动态数据更新,无需重新加载页面

我正在尝试创建类似Google Suggest Tool的内容(通过建议api http://suggestqueries.google.com/complete/search?output=toolbar&hl=ru&q=query)

我正在监听输入变化,并发送数据去GET:

$("#search_form_input").keyup(function(){
var some_var = $(this).val();
   $.ajax({
      url: "",
      type: "get", //send it through get method
      data:{jsdata: some_var},
      success: function(response) {

      },
      error: function(xhr) {
        //Do Something to handle error
      }
    });
Run Code Online (Sandbox Code Playgroud)

之后,我正在处理这些数据并将其发送到Google API并在Python中得到响应:

@app.route('/', methods=['GET', 'POST'])
def start_page_data():
    query_for_suggest = request.args.get('jsdata')

    if query_for_suggest == None:
        suggestions_list = ['',]
        pass
    else:
        suggestions_list = []
        r = requests.get('http://suggestqueries.google.com/complete/search?output=toolbar&hl=ru&q={}&gl=in'.format(query_for_suggest), 'lxml')
        soup = BeautifulSoup(r.content)
        suggestions = soup.find_all('suggestion')
        for suggestion in suggestions:
            suggestions_list.append(suggestion.attrs['data'])
        print(suggestions_list)
    return render_template('start_page.html', suggestions_list=suggestions_list)
Run Code Online (Sandbox Code Playgroud)

在Jinja尝试动态打印HTML:

        <label …
Run Code Online (Sandbox Code Playgroud)

javascript python jquery jinja2 flask

19
推荐指数
1
解决办法
4万
查看次数

输入宽度采用form-inline bootstrap 3

我不明白,我如何在Bootstrap 3中自定义输入(窗体控制)宽度?

<header>
    <div class="container">
        <div class="row">
            <form role="form" class="form-inline">
                  <div class="form-group">
                      <input type="text" class="form-control" placeholder="???????? ?????????????" id="search"> 
                  </div>
                    <input type="button" class="btn  btn-success" value="?????" onclick="window.location.href = '/result/'+document.getElementById('search').value">
            </form>
        </div>
    </div>
</header>
Run Code Online (Sandbox Code Playgroud)

没有一些样式(如像素宽度),我可以这样做吗?

html css jquery twitter-bootstrap twitter-bootstrap-3

11
推荐指数
1
解决办法
3万
查看次数

在 Python 3 中将字典列表转换为 CSV

我得到了不同长度甚至不同(key: values)对的字典列表。例如:

[
    {'key1': 'value1', 'key3':'value3'},
    {'key1': 'someValue', 'key2':'value2', 'key3':'value3'},
    {'anotherKey': 'anotherValue', 'key1': 'value1', 'key2':'value2'},
    {'anotherKey': 'anotherValue', 'anotherKey1': 'anotherValue1', 'key1': 'value1', 'key2':'value2', 'key3':'value3'},
]
Run Code Online (Sandbox Code Playgroud)

我需要创建CSV所有键作为标题和值的文件。如果键不在当前字典中,则设置默认值(例如“-”)。在CSV从例子应该寻找这样的:

在此处输入图片说明

我正在为我的字典列表尝试此代码,但它返回一个错误:

listOfDicts = [
    {'key1': 'value1', 'key3':'value3'},
    {'key1': 'someValue', 'key2':'value2', 'key3':'value3'},
    {'anotherKey': 'anotherValue', 'key1': 'value1', 'key2':'value2'},
    {'anotherKey': 'anotherValue', 'anotherKey1': 'anotherValue1', 'key1': 'value1', 'key2':'value2', 'key3':'value3'},
]

keys = listOfDicts[0].keys()
with open('test.csv', 'a') as output_file:
    dict_writer = csv.DictWriter(output_file, fieldnames=keys, delimiter='@')
    dict_writer.writeheader()
    dict_writer.writerows(listOfDicts)
Run Code Online (Sandbox Code Playgroud)

错误:

ValueError: dict contains fields not in fieldnames: 'key2' …
Run Code Online (Sandbox Code Playgroud)

python csv dictionary list python-3.x

7
推荐指数
1
解决办法
4385
查看次数

Python BeautifulSoup 替换 img src

我正在尝试解析站点中的 HTML 内容,更改 href 和 img src。A href 更改成功,但 img src 未更改。

它在变量中发生了变化,但在 HTML 中没有发生变化(post_content):

<p><img alt="alt text" src="https://lifehacker.ru/wp-content/uploads/2016/08/15120903sa_d2__1471520915-630x523.jpg" title="Title"/></p>
Run Code Online (Sandbox Code Playgroud)

不是 _http://site.ru...

<p><img alt="alt text" src="http://site.ru/wp-content/uploads/2016/08/15120903sa_d2__1471520915-630x523.jpg" title="Title"/></p>
Run Code Online (Sandbox Code Playgroud)

我的代码

if "app-store" not in url:
        r = requests.get("https://lifehacker.ru/2016/08/23/kak-vybrat-trimmer/")
        soup = BeautifulSoup(r.content)

        post_content = soup.find("div", {"class", "post-content"})
        for tag in post_content():
            for attribute in ["class", "id", "style", "height", "width", "sizes"]:
                del tag[attribute]

        for a in post_content.find_all('a'):
            a['href'] = a['href'].replace("https://lifehacker.ru", "http://site.ru")

        for img in post_content.find_all('img'):
            img_urls = img['src']
            if "https:" not in img_urls:
                img_urls="http:{}".format(img_urls) …
Run Code Online (Sandbox Code Playgroud)

html python href src

5
推荐指数
1
解决办法
9315
查看次数

Python请求在localhost中返回504

我运行werkzeug服务器(通过Flask)并尝试通过请求lib连接到localhost并得到504错误,但如果在浏览器中打开http://127.0.0.1:5000/ - 一切正常.

我的代码:

import requests
r = requests.get('http://127.0.0.1:5000/')
print(r.content)
Run Code Online (Sandbox Code Playgroud)

回复错误:

b'\ r \n\r \nERROR:网关超时\ r \n

错误:网关超时

\ r \n\r \n\r \n

在尝试检索URL http://127.0.0.1:5000/时:

\ r \n
  • 拒绝连接
\ r \n\r \n

您的缓存管理员是网站管理员.\ r \n\r \n生成星期四,2017年4月6日11:31:09 GMT by 10.101.0.1(Mikrotik HttpProxy)\ r \n\r \n'

烧瓶代码:

from flask import Flask, request, render_template, jsonify, Response
import geoLocation
import models
import json
from bson.json_util import dumps
from bson import json_util



app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    return 'OK'
.... …
Run Code Online (Sandbox Code Playgroud)

python timeout werkzeug python-requests

5
推荐指数
1
解决办法
8636
查看次数

Flask request.args.get获取所有参数(Python)

我如何从烧瓶中的URL解析所有GET参数?我尝试使用request.args.get,但它适用于特定的GET参数(预定义),但我需要从我的大URL解析它(例如:http://site.ru/?a = 1&b = 2& c = 3&some_string = string ..)

python get flask

4
推荐指数
1
解决办法
2万
查看次数

vue.js 为每 6 个循环元素插入块

我提供了通过循环呈现的卡片列表。每 3rd col (bootstrap) 元素我添加行 div。现在我需要为每 6 个元素添加另一个 col 元素(横幅块)。为了渲染这样的东西:

在此处输入图片说明

我该如何实现?

我现在的代码

<div class="row" v-for="i in Math.ceil(offers.length / 3)">
    <div class="col-xl-4 col-lg-4 col-md-6 col-sm-12 col-12" v-for="offer in offers.slice((i-1)*3, i*3)">
        <h2>{{offer.name}}</h2>
        <h2>{{offer.desc}}</h2>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

javascript loops vue.js vue-component

4
推荐指数
2
解决办法
4657
查看次数

在Bootstrap 3中设置'select'元素的高度?

如何select在Bootstrap 3中设置元素的高度?

这是我的代码:

<select id="lst-size" name="p_size" class="col-lg-12 col-md-12 col-sm-4 col-xs-12">
  <option value="<?php echo "size1" ?>" selected="selected"><?php echo "{$rst_catalog['p_size1']}" ?></option>
  <option value="<?php echo "size2" ?>"><?php echo "{$rst_catalog['p_size2']}" ?></option>
  <option value="<?php echo "size3" ?>"><?php echo "{$rst_catalog['p_size3']}" ?></option>
  <option value="<?php echo "size4" ?>"><?php echo "{$rst_catalog['p_size4']}" ?></option>
  <option value="<?php echo "size5" ?>"><?php echo "{$rst_catalog['p_size5']}" ?></option>
  <option value="<?php echo "size6" ?>"><?php echo "{$rst_catalog['p_size6']}" ?></option>
</select>
Run Code Online (Sandbox Code Playgroud)

现场网站.

css height select twitter-bootstrap twitter-bootstrap-3

3
推荐指数
2
解决办法
3万
查看次数

带侧边栏的Bootstrap完全100%高度

我无法理解为什么右侧边栏的高度,而不是100%,当我向下滚动页面时,背景被中断.

<nav id="nav" class="nav-primary hidden-xs nav-vertical">
<ul class="nav affix-top" data-spy="affix" data-offset-top="50">
<li><a href=""><i class="icon-user"></i> ???????</a></li>
<li><a href=""><i class="icon-bar-chart"></i> ???????</a></li>
<li><a href=""><i class="icon-sitemap"></i> ??????</a></li>
<li><a href=""><i class="icon-signal"></i> ?????? (??????????)</a></li>
<li><a href=""><i class="icon-envelope-alt"></i> ??????????? (10)</a></li>
</ul>
</nav>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

生活中的例子在这里

html css height sidebar twitter-bootstrap

2
推荐指数
1
解决办法
1万
查看次数

python硒在循环中查找子元素

我需要解析页面上所有父元素中的一些子元素。

创建页面上所有文章的列表

article_elements = driver.find_elements_by_tag_name('article')
Run Code Online (Sandbox Code Playgroud)

并绑定以获得for循环中的子元素并将所有结果附加到列表之后

for article in article_elements:
    title = article.find_element_by_xpath('//article/h2').text
    share_count = article.find_element_by_xpath('//footer/div/a/span').text
    poinst = article.find_element_by_xpath('//footer/div[2]/div[1]/div[3]').text
    meta_info_list.append({'title':title, 'share count':share_count, 'points':poinst})
Run Code Online (Sandbox Code Playgroud)

循环结束后,我得到了40次相同的文章meta(第一篇文章)

{'share count': u'66', 'points': u'53 points', 'title': u'25+ Random Acts Of Genius Vandalism'}
{'share count': u'66', 'points': u'53 points', 'title': u'25+ Random Acts Of Genius Vandalism'}
{'share count': u'66', 'points': u'53 points', 'title': u'25+ Random Acts Of Genius Vandalism'}
{'share count': u'66', 'points': u'53 points', 'title': u'25+ Random Acts Of Genius Vandalism'}
... 40 times
Run Code Online (Sandbox Code Playgroud)

我的整个代码 …

python selenium loops for-loop web-scraping

2
推荐指数
1
解决办法
3645
查看次数

Python 检查 csv 文件中的值是否存在

我得到了 URL 列表,例如:

urls_list = [
    "http://yandex.ru",
    "http://google.ru",
    "http://rambler.ru",
    "http://google.ru",
    "http://gmail.ru",
    "http://mail.ru"
]
Run Code Online (Sandbox Code Playgroud)

我需要打开 csv 文件,检查文件中列表中的每个值是否跳到下一个值,否则(如果值不在列表中)在列表中添加该值。

结果:第一次运行 - 添加所有行(如果文件为空),第二次运行 - 不执行任何操作,因为所有元素都已在文件中。

编写了代码,但它的工作完全不正确:

import csv


urls_list = [
    "http://yandex.ru",
    "http://google.ru",
    "http://rambler.ru",
    "http://google.ru",
    "http://gmail.ru",
    "http://mail.ru"
]



with open('urls_list.csv', 'r') as fp:
    for row in fp:
        for url in urls_list:
            if url in row:
                print "YEY!"
            with open('urls_list.csv', 'a+') as fp:
                wr = csv.writer(fp, dialect='excel')
                wr.writerow([url])
Run Code Online (Sandbox Code Playgroud)

python csv loops if-statement

1
推荐指数
1
解决办法
2万
查看次数

从Python中的字符串中删除特定的重复字符

我如何才能从字符串中删除特定的重复字符,只有当它们在Python中一个接一个地出现时?例如:

A 有字符串

string = "Hello _my name is __Alex"
Run Code Online (Sandbox Code Playgroud)

仅当重复的 _ 一一对应 __ 并得到如下字符串时,我才需要删除它们:

string = "Hello _my name is _Alex"
Run Code Online (Sandbox Code Playgroud)

如果我使用 set 我得到这个:

string = "_yoiHAemnasxl"
Run Code Online (Sandbox Code Playgroud)

python string text set python-3.x

-2
推荐指数
1
解决办法
3141
查看次数