这是我编写的webscraping代码,但是我想浏览5个不同的url并将它们连接到一个数据帧中,有什么办法可以做到?还是通过单词的组合来循环? (因为网址:“产品” +“营销”)
先感谢您!
这是代码:
x = urllib.request.urlopen('https://h1bdata.info/index.php?em=&job=PRODUCT+MARKETING+&city=&year=All+Years')
soup = BeautifulSoup(x)
table = soup.find_all('tr')
labels = [] #list of the header column
for attr in table[0].find_all('th'):
labels.append(attr.get_text())
data = []
for record in table[1:]:
record_list = []
for string in record.find_all('td'):
ls = string.get_text().replace(',','')
if ls.isnumeric():
record_list.append(int(ls))
else:
record_list.append(ls)
data.append(record_list)
df = pd.DataFrame(data,columns=labels)
这可能行不通,因为您必须以不同的方式处理标签,但是我在想些类似的事情吗?这也假定您的列/标签在所有5页中都相同。