我有一个包含第2列A和B的csv文件,我想用beautifulsoup废弃所有文件
URL的组成如下:http://.../search?info=A&who=B
如何创建循环?
我的代码
from bs4 import BeautifulSoup
import requests
import json
import csv
with open('input.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
url = ".../search?info={}&who={}".format(row[0], row[1])
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, "html5lib")
for p in soup.find_all(class_="crd"):
b = p.find(class_="info")
if b['data-info'] is not None:
j = json.loads(b['data-info'])
data= p.h2.a.string
答案 0 :(得分:0)
import csv
with open('input.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
url = url = ".../search?info={}&who={}".format(row[0], row[1])
#rest of your logic