小编Kev*_*vin的帖子

是否可以使用BeautifulSoup编辑内联代码?

我知道用beautifulsoup编辑文本的能力,是否可以编辑href链接?我希望能够说出<a href="/foo/bar/">并使用beautifulsoup来改变它<a href="http://www.foobarinc.com/foo/bar/">.我不确定如何使用beautifulsoup来做到这一点?任何帮助,非常感谢.

python beautifulsoup

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

Django中的IntegrityError

我在其中一种表单中添加了Many2Many字段,现在在提交时收到IntegrityError。确切的错误文本是

/add_person/hireterm_person.mail_lists的IntegrityError不能为NULL

在我添加新字段之前,它运行良好。当我查看有关调试更改的POST数据时,我看到它已通过,因此我不知道中断发生在哪里。

楷模

from django.db import models
from django.forms import ModelForm
from django import forms
from django.contrib.auth.models import User

class Mailists(models.Model):
    name = models.CharField(blank=True, max_length=100)
    email = models.CharField(blank=True, max_length=100)

    def __unicode__(self):
        return u'%s' % (self.name)

class Person(models.Model):
    ROLE_CHOICES = (
        ('Mrkt', 'Marketing'),
        ('Fin/Off', 'Finance / Office'),
        ('Care', 'Care'),
        ('Sales', 'Sales'),
        )
    ROLE_TYPE = (
        ('Full', 'Full Time'),
        ('Part', 'Part Time'), 
        ('Intern', 'Intern'),
        )

    first_name = models.CharField(blank=True, max_length=100)
    last_name = models.CharField(blank=True, max_length=100)
    date_added = models.DateField(auto_now_add=True)
    date_start = models.DateField(auto_now=False)
    role = …
Run Code Online (Sandbox Code Playgroud)

python django

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

划分为if语句

在Python中,如果我有一个范围,并且我想迭代它并将每个数字除以另一个数字,我可以在if语句中执行此操作.

a = range(20)
for i in a:
   if i / 3 == True:
      print i
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
5710
查看次数

for循环中的print语句只执行一次

我在教自己蟒蛇.我正在考虑小程序,想出了做基诺数字生成器的想法.对于任何不知道的人,你可以选择4-12个数字,范围1-80,以匹配.所以第一部分是询问有多少数字,第二部分是生成数字.我想出来了

x = raw_input('How many numbers do you want to play?')
for i in x:
   random.randrange(1,81)
print i
Run Code Online (Sandbox Code Playgroud)

哪个不起作用,它打印x.所以我想知道最好的方法.做一个random.randrange函数?我如何根据用户输入调用x次.

一如既往,提前感谢您的帮助

python

0
推荐指数
1
解决办法
893
查看次数

使用列表对象在Python中查找字典中的项目

我有一个wxPython核对表框,它返回一个整数列表.我想使用整数来查找字典中的项目.我不确定最好的方法.有什么建议?

python dictionary list

0
推荐指数
1
解决办法
118
查看次数

在BeautifulSoup中传递NoneType属性

我正在使用beautifulstonesoup和python从Google解析XML提要,并且效果很好.我也在创建一个csv并将其上传到Google Docs,这也很好.问题是当我遇到xml中的空文本属性时,解析器就会停止.现在不是问题,因为所有属性都有数据,但是第一次没有,它会破坏.

代码:

import atom
import gdata.auth
import gdata.contacts
import gdata.contacts.client
import gdata.docs.service
import gdata.docs.data
from BeautifulSoup import BeautifulStoneSoup as Soup
import csv

email = 'admin@domain.com'
password = 'password'
domain = 'domain.com'

ms_client = gdata.docs.service.DocsService()
gd_client = gdata.contacts.client.ContactsClient(domain=domain)
gd_client.ClientLogin(email, password, 'profileFeedAPI')
ms_client.ClientLogin(email, password, 'peopleCSVupload')

profiles_feed = gd_client.GetProfilesFeed('https://www.google.com/m8/feeds/profiles/domain/domain.com/full?max-results=300')

soup = Soup(str(profiles_feed), selfClosingTags=['ns0:category','ns3:status', 'ns0:link','ns1:email'])

a = soup.findAll('ns0:entry')
f = open('C:\\people.csv', 'wb')

writer = csv.writer(f, quoting=csv.QUOTE_NONE, escapechar =' ')

for entry in a:
    writer.writerow([entry.find('ns1:familyname').text + ',' + entry.find('ns1:givenname').text + ',' + entry.find('ns1:fullname').text + …
Run Code Online (Sandbox Code Playgroud)

python xml

0
推荐指数
1
解决办法
1895
查看次数

标签 统计

python ×6

beautifulsoup ×1

dictionary ×1

django ×1

list ×1

xml ×1