这是我用来抓取名称和网址的代码,但每个名称都以~
. 我想删除~
部分。我尝试过使用str_replace
,但从外观上看似乎不对。(也对其进行了测试,结果相同)
foreach ($div_category as &$div){
$a_list = $div->find("a");
foreach ( $a_list as &$anchor){
//put the data into an array and then write array out to a csv file.
$csv_array=array($anchor->plaintext, $anchor->getAttribute("href") );
$anchor = str_replace( '~', ' ', $anchor);
fputcsv($csv_out, $csv_array);
当前结果示例:
name url
~john www.john.com
~bob www.bob.com
~rob www.rob.com