我有一个python webscrapping代码,运行得非常好,如果我不插入任何结果在数据库中。即当我注释掉的代码TypeError:并非在字符串格式化过程中转换的所有参数
“”“ 连接到数据库,并把数据放入 ‘’”
db= MySQLdb.connect("localhost","XXX","XXX","hmm_Raw_Data")
cursor=db.cursor()
#checking phase to stop scrapping
sql = """SELECT Short_link FROM RentalWanted WHERE Short_link=%s"""
rows = cursor.execute(sql,(link_result))
if rows>=1:
duplicate_count+=1
print duplicate_count
# if duplicate_count>=15:
# print "The program has started getting duplicates now- The program is terminating"
# sys.exit()
else:
query="""INSERT INTO RentalWanted
(Sale_Rent,
Type,
Area,
Nearby,
Title,
Price,
PricePerSqrFt,
Bedroom,
Agency_Fee,
Bathroom,
Size,
ZonedFor,
Freehold,
Prop_ref,
Furnished_status,
Rent_payment,
Building_info,
Amenities,
Trade_name,
Licence,
RERA_ID,
Phone_info,
Short_link)
values(
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s)"""
cursor.execute(query,(
Sale_Rent_result,
Type_result,
area_result,
nearby_result,
title_result,
price_result,
Pricepersq_result,
bedroom_result,
agencyfee_result,
bathroom_result,
size_result,
Zoned_for_result,
Freehold_result,
propertyref_result,
furnished_result,
rent_is_paid_result,
building_result,
Amenities_result,
tradename_result,
licencenum_result,
reraid_result,
phone_result,
link_result))
db.commit()
cursor.close()
db.close()
把上面的代码时,我得到的错误,这部分是这样的:
Traceback (most recent call last): File "RentalWanted.py", line 461, in <module>
getting_urls_of_all_pages() File "RentalWanted.py", line 45, in getting_urls_of_all_pages
every_property_in_a_page_data_extraction(a['href']) File "RentalWanted.py", line 365, in every_property_in_a_page_data_extraction
rows = cursor.execute(sql,(link_result)) File "/usr/lib/python2.6/site-packages/MySQL_python-1.2.5-py2.6-linux-x86_64.egg/MySQLdb/cursors.py", line 187, in execute
query = query % tuple([db.literal(item) for item in args]) TypeError: not all arguments converted during string formatting
我认为我正在做的查询有问题。
任何人都可以帮我弄清楚哪一部分需要修复。我花了几个小时,但不知道我在哪里错了
感谢
有人吗?帮助我PLZ。谢谢 – Newbie 2014-12-07 14:10:33